TypeScript
React Node vs React JSX Element
JSX Elementis an element that react.createElement is allowed to create, simply the object of virtual domReact.ReactNodemeans value of a component, but also a list of jsx elements
declare namespace React {
type ReactNode =
| ReactElement
| string
| number
| ReactFragment
| ReactPortal
| boolean
| null
| undefined;
}const node: React.ReactNode = <div />;
const node2: React.ReactNode = "hello world";
const node3: React.ReactNode = 123;
const node4: React.ReactNode = undefined;
const node5: React.ReactNode = null;
const node6: JSX.Element = "hello world";
// Error : Type 'string' is not assignable to type 'Element'.Best Practice & Use Cases
References
Last updated
Was this helpful?