Typescript React Types

Hey everyone

I’m doing Mosh’s React 18 for Beginners course. In Building Components, Lesson 11. When passing more complex children as props to a React component (comprising of other HTML elements), Mosh sets the children prop to the type ReactNode.

My question is, how and where would I find that information? If for example there are more types.

Cheers

Here is some documentation on react props. This what ya are looking for?

Thanks for the reply, I probably should have explained it better.

It’s a TypeScript thing, when defining the values of function arguments; one argument that will come from props, is the children object. In this example is more than simply some text, it could contain HTML. The TypeScript type is set to ReactNode

interface Props { children: ReactNode; onClose: () => void; }

Which is an import from react: import { ReactNode } from "react";

How do I find out what the children object should be?

Cheers

It’s a tricky topic i’ve tried defining props for a form submission and pass the data to a usestate ended up having to pass a html fotm element instead of my prop and that made it work.

I could use a refresher tbh from the course.

1 Like