Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Why do ReactDOMServer and ReactDOM give the "root.hydrate is not a function" error

When creating an app using create-react-app I get the following error when trying to use hydrate instead of the default .render. Here is the src/index.js file's contents.

import React from 'react';
import ReactDOMServer from 'react-dom/client';
import './index.css';
import App from './App';

const root = ReactDOMServer.createRoot(document.getElementById('root'));
root.hydrate(
 <React.StrictMode>
   <App />
 </React.StrictMode>
);

Running the above code npm start produces the following error

Uncaught TypeError: root.hydrate is not a function

The error is not present if I change the .hydrate back to .render and I am not sure why this is happening.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Thank you @PR7 that worked perfectly.

Please note, as my original file syntax was slightly different (from your example), I have written my "before" and "after" below; in case it can help anyone else.

// Before
import ReactDOM from 'react-dom/client';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.hydrate(
  <React.StrictMode>
   <App />
 </React.StrictMode>
);

// After

import { hydrateRoot } from 'react-dom/client';
const container = document.getElementById('root');
const root = hydrateRoot(container, <App />);
about 4 years ago · Juan Pablo Isaza Report

0

hydrate has been replaced with hydrateRoot in React 18.

hydrateRoot(container, element[, options])

You can check for more info about hydrateRoot here : Documentation

// Before React 18
import { hydrate } from 'react-dom';
const container = document.getElementById('app');
hydrate(<App tab="home" />, container);

// After React 18+
import { hydrateRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = hydrateRoot(container, <App tab="home" />);
// Unlike with createRoot, you don't need a separate root.render() call here.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!