Runtime validation
Validate an unknown prop or external value before rendering or inspecting it.
React 19+ · Type Alias
React elements are UI descriptions created by JSX or createElement. Use isValidElement to distinguish them from other React nodes and arbitrary values.
A React element is the object description produced by JSX or createElement. Use isValidElement when code receives an unknown value and must distinguish an element from other renderable nodes such as strings, numbers, or arrays.
isValidElement(value)| Name | Type | Description |
|---|---|---|
value | unknown | The value to test for React-element identity. |
Returns true when value is a React element; otherwise returns false.
import { isValidElement } from 'react';
function Preview({ value }: { value: unknown }) {
return isValidElement(value) ? value : <p>Not an element</p>;
}
export default function App() {
return <Preview value={<strong>Hello</strong>} />;
}Checks an unknown value before treating it as a React element.
Validate an unknown prop or external value before rendering or inspecting it.
Branch between element-specific handling and fallback content.
Accept either JSX-created elements or createElement results in a utility.
createElementisValidElementJSX