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

1.4K
Visualizações
Hydration error due to if statement in Next.js

I am getting three errors due to the if statement in my _app.js file.

Error: Hydration failed because the initial UI does not match what was rendered on the server.
Error: Hydration failed because the initial UI does not match what was rendered on the server.
Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.

What is the cause of the error and how do I fix it?

import '../styles/globals.css'
import Popup from "../components/register-popup.js";
import { getCookies, setCookies, removeCookies } from 'cookies-next';

var isValid = getCookies("noPopup").noPopup != "valid";

function MyApp({ Component, pageProps }) {
  if (isValid) {
    return (
      <div>
        <Popup />
      </div>
    )
  } else {
    return (
      <div>
        <Component {...pageProps} />
      </div>
    )
  }
}

export default MyApp
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

change your code

import '../styles/globals.css'
import Popup from "../components/register-popup.js";
import { getCookies, setCookies, removeCookies } from 'cookies-next';


function MyApp({ Component, pageProps }) {
  const isValid = getCookies("noPopup").noPopup != "valid";

  if (isValid) {
    return  <Popup />    
  } else {
    return  <Component {...pageProps} />
  }
}

export default MyApp

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