props.children is not defined.
I have this component.
My IDE is telling me that
props.children
isn't defined somehow. I'm guessing this is just some typing problem? How would I fix this?7 Replies
It comes from your props type. You need to include the children there. <AuthContextProps> also need to have
children
. Another way, a bit more verbose, would be to have <AuthContextProps & ParentProps>
where ParentProps is a built-in that only has children
as a propHmm. So, can I just have my Props interface extend ParentProps? Or is that not recommended?
That I think is purely user-land. Whatever fits your need. ParentProps is just
children: JSX.Element
nothing you couldn't replicateAh. Okay. Much appreciated.
There's ParentComponent<Props>, too
Oh. Good to know. That’s actually a lot easier. 🙂
We try to keep our types as helpful as possible. Component means that you define children yourself, ParentComponent is the usual choice for components with children and VoidComponents is for components that would not render elements (so you don't accidentially add them).