Sophie Au

Software Developer, Web Designer, Tea Enthusiast

Typing React Components

12 April 2020

When using TypeScript you won't get around having to type React components. This usually happens when you want to pass them as props. When you get to that point you suddenly have a ton of different types to choose from. Below are the main contenders with pseudo-coded typings:

type ReactElement = html | JSX.Element // html isn't actually a valid type though
type ReactText = string | number;

type ReactChild = ReactElement | ReactText;
type ReactNode = ReactChild | boolean | null | undefined; //or an array of them