JSX.Element Vs ReactNode Vs ReactElement
Web/React
When to use JSX.Element vs ReactNode vs ReactElement?
A ReactElement is an object with a type and props.
A ReactNode is a ReactElement, a ReactFragment, a string, a number or an array of ReactNodes, or null, or undefined, or a boolean.
JSX.Element is a ReactElement, with the generic type for props and type being any. so they are more or less the same.
Components return:
And functions are "stateless components":
- TS class component: returns ReactNode with render(), more permissive than React/JS
- TS function component: returns JSX.Element | null, more restrictive than React/JS