# Fix "ReactDOM.render is no longer supported in React 18. Use createRoot instead"

Yes. An agent finds every ReactDOM.render and the entry point that re-renders on store changes, moves them to createRoot, and checks the app under React 18 and 19.

[Run this on Rush](https://cloud.getrush.ai/run/fix-reactdom-render-no-longer-supported/react/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

React 18 kept `ReactDOM.render` but logs `Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17.` React 19 removed it: on `react-dom` 19.3.1, `ReactDOM.render` is `undefined` and calling it throws `TypeError: ReactDOM.render is not a function`. `createRoot` lives in `react-dom/client` on both; on 18.3.1 it is also exported from `react-dom`, on 19 it is not. So an app on React 17 that bumps one major gets a warning and the old behaviour, and one that bumps two gets a blank page and a thrown error at start-up.

redux-saga/redux-saga-beginner-tutorial is the companion repository for the Redux-Saga beginner tutorial, a counter wired to a Redux store. `package.json` pins `react` and `react-dom` at `^17.0.2` with `redux ^4.1.2` and `redux-saga ^1.1.3`, builds with Browserify and Babel through `budo` in the `start` script, and `index.html` loads `build.js` into a `root` div. `main.js` is the whole entry point: it creates the store on line 10, defines a `render` function on lines 14 to 22 that calls `ReactDOM.render(<Counter ... />, document.getElementById('root'))`, calls it once on line 24 and subscribes it to the store on line 25, so every dispatch renders again. `Counter.js` is a function component with two buttons and `PropTypes`; `reducers.js` handles `INCREMENT`, `DECREMENT` and `INCREMENT_IF_ODD`.

The port is small but the re-render pattern is the part people get wrong. The agent reads `main.js`, confirms there is one `ReactDOM.render` and that it runs on every store change, and rewrites it so the root is created once, `const root = createRoot(document.getElementById('root'))` from `react-dom/client`, and `render` calls `root.render(<Counter ... />)` each time the store notifies. Creating a root inside `render` would create a new root per click, and the pull request says why it did not. `react` and `react-dom` move to the same major in `package.json`, and `@babel/preset-react` is checked for the JSX transform the new major expects.

To verify without a browser, the agent installs React 18 and renders `main.js`'s component into a jsdom document, dispatching `INCREMENT` and asserting the text `Clicked: 1 times` appears, and watches the console for the `createRoot` warning, which must be gone. It repeats that under React 19 to show the same code runs where `ReactDOM.render` no longer exists. The existing `test` script expects a `sagas.spec.js` the repository does not have, which the pull request notes without inventing one.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This React app logs 'ReactDOM.render is no longer supported in React 18. Use createRoot instead' after upgrading react and react-dom. Read package.json and report the react, react-dom and build tooling versions. Install the dependencies and reproduce the warning by rendering the entry point into a jsdom document; then install react and react-dom 19 in a scratch copy and record what happens to the same code. Find every ReactDOM.render, ReactDOM.hydrate and unmountComponentAtNode call with file and line, and note any that run more than once, such as a render function subscribed to a store. Port them to createRoot from react-dom/client, creating the root exactly once and calling root.render on each update; explain in the pull request why the root must not be created inside the subscribed function. Bump react and react-dom to the same major in package.json and check the Babel preset still handles JSX. Write a test that renders the entry point in jsdom, dispatches a store action, asserts the rendered text, and fails if the createRoot warning is logged; run it under React 18 and React 19. Do not add a UI framework or change the build tool. Open a pull request with the call list, the console output before and after, and the test output on both versions.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that rewrites the entry point in `main.js`, bumps `react` and `react-dom` in `package.json`, and adds a jsdom test. The description leads with the console output before and after: the React 18 warning on the old code, the `TypeError` on React 19, and a clean console on the ported code under both.

The record of the run holds both installs, the two renders, and the test asserting `Clicked: 1 times` after a dispatch. For a counter that re-renders on every store change, the test is also the evidence that one root is reused rather than created per update, because a root created per click would still pass a single render and the agent is asked to show the subscription path.

Before merging, a reviewer runs `npm start` and clicks the buttons, since the sandbox test runs in jsdom and not in a browser with the Browserify bundle. If the project also has a hydration entry for server rendering, that needs `hydrateRoot` and the pull request says whether it found one.

## Run it on every pull request

A React major bump arrives as a pull request. An automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize`, with a prompt that asks for the check above on any pull request that changes `react` or `react-dom` in `package.json`, starts one run per such pull request. The trigger adds the pull request to the prompt and fills in no placeholder, and a pull request opened by a bot fires no `github` trigger, so Dependabot's bumps need the second path.

That path is a `schedule` trigger on the Project, weekly, with the prompt "for each open pull request that bumps react, install it, render the entry point in jsdom, and comment with whether the createRoot warning or a render error appears". A run an automation starts has its own `max_runs_per_hour` cap and is read from its session like any other.

## Why run it on Rush?

The warning is easy to silence and easy to silence wrongly. Whether the root is created once or once per update only shows under a store subscription with several dispatches, and checking that under two React majors means two installs and a DOM. The agent does both in a sandbox and leaves the console output of each run beside the diff, so the reviewer reads what happened rather than what the diff suggests.

Small React apps come in batches: tutorials, demos and internal tools forked from the same starter. The same request goes to each repository as its own session with its own `package.json`, as many at once as the key's `max_concurrent` limit allows, and each pull request shows the test on both majors for its own entry point.

## Frequently asked questions

### Can I stay on React 18 and ignore the warning?

The app keeps working, as the message says, with React 17 behaviour. The next bump removes the call: on `react-dom` 19.3.1 `ReactDOM.render` is `undefined` and the app throws at start-up. The port is the same either way, so the pull request makes it while the warning is still only a warning.

### Where do I import createRoot from?

From `react-dom/client`. On 18.3.1 `react-dom` itself also exports it; on 19 it does not, so the import from `react-dom/client` is the one that works on both majors, and it is what the pull request uses.

### Why not create the root inside the render function?

Because `main.js` calls `render` on every store change. A root created there would be a new root on every dispatch instead of an update to one, so the pull request creates the root once at module level and calls `root.render` from the subscribed function.

### Does the test cover the Browserify build?

No. It renders the entry point in jsdom with Babel handling JSX, which is enough to prove the port and catch the warning. The `npm start` bundle through `budo` is left for the reviewer to click through, and the pull request says so.

### Does the agent change redux or redux-saga?

No. The store, the reducer and the subscription pattern stay; only the rendering call changes. The request forbids adding a UI framework or changing the build tool, so the diff is the entry point, the two version lines and the test.

## More React jobs

- [Turn Sentry Errors Into Fix Pull Requests for a React App](https://getrush.ai/run/fix-sentry-errors/react/)
- [Fix a Failed Vercel Deployment of a React App](https://getrush.ai/run/fix-vercel-build-failures/react/)
- [Fix Vulnerable Dependencies in a React App](https://getrush.ai/run/fix-vulnerable-dependencies/react/)

## More jobs like this: Fix a bug from an alert

- [Fix "TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'" in pandas 2](https://getrush.ai/run/fix-read-csv-error-bad-lines-type-error/pandas/)
- [Fix "Error: req#logout requires a callback function" in Passport 0.6 and later](https://getrush.ai/run/fix-req-logout-requires-a-callback-function/passport/)
- [Fix "LookupError: Resource punkt_tab not found" in word_tokenize](https://getrush.ai/run/fix-resource-punkt-tab-not-found/nltk/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
