In react you can set the propType of the props that come into a component. For one of my props I want the value to either be null or a line of JSX. The React docs don't cover what propType should be used for JSX.
When testing this I found that it wouldn't throw errors when using the propTypes of object or element. When using another such as symbol I would get an error that said it was an object. If it was an object surely it should complain when it's an element.
What is the correct propType for JSX?
PropTypes are a good first line defense when it comes to debugging your apps. But before getting into detail about PropTypes, we have to understand the concept of props. Props are the read-only properties that are shared between components to give the unidirectional flow of React a dynamic touch.
Class components So, the type of the children prop in a class component is ReactNode .
You want to use JSX inside your props You can simply use {} to cause JSX to parse the parameter. The only limitation is the same as for every JSX element: It must return only one root element.
“Props” is a special keyword in React, which stands for properties and is being used for passing data from one component to another.
Try using this propType...
React.PropTypes.element
PropTypes.node
or PropTypes.element
can be used
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With