Create elements without JSX
A project cannot compile or embed JSX syntax.
React 19+ · Function
createElement constructs a React element from a type, props, and optional children. It is the programmatic alternative to JSX when direct element construction is needed.
Call createElement with a valid element type, an object or null for props, and any number of React-node children. It returns a React element object; special ref and key values are exposed separately from the ordinary props, while omitted ones become null.
createElement(type, props, ...children)| Name | Type | Description |
|---|---|---|
type | string | function | class | special component | A valid React component type, such as an intrinsic tag-name string, function component, class component, or special component. |
props | object | null | An object containing props, or null, which is treated like an empty object. |
...children | ReactNode[] | Zero or more React nodes, including elements, strings, numbers, portals, empty nodes, and arrays of React nodes. |
A React element object containing the supplied type, props excluding ref and key, and ref and key fields.
import { createElement } from 'react';
function Greeting({ name }: { name: string }) {
return createElement('h1', { className: 'greeting' }, `Hello ${name}`);
}
const element = createElement(Greeting, { name: 'Ada' });
console.log(element);Creates a component element without JSX, passing a typed prop and a text child.
A project cannot compile or embed JSX syntax.
A library or renderer needs to build element descriptions from runtime values.
A component tree is generated from a dynamic tag or component reference.
createElement constructs a React element from a type, props value, and zero or more children. The type may be an intrinsic tag name or a React component, and props may be an object or null.
Follow-up: What can children contain? Any React nodes, including elements, strings, numbers, portals, empty nodes, and arrays of React nodes.
The returned element records the supplied type and props, excluding ref and key from element.props. A missing ref or key is represented as null, and key values are coerced to strings.
Follow-up: Where should code look for a key supplied during creation? On the returned element's key field, rather than in element.props.key.
createElement is the non-JSX alternative for creating React elements. It is useful when JSX cannot be used, but the documentation says JSX is normally preferred.
Follow-up: Why might a codebase still use it? A renderer, library, generated code path, or environment may need to construct elements directly without JSX syntax.
JSXFragmentisValidElementcreateRoot