Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda