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

594
Visualizações
Why can't I access the window in Next.js app '_app.js'?

I have a Next.js app where I want to load the application and then check for Network access with a custom modal dialog that displays if the user disconnects to the internet. I set up an _app.js file for my application to set up the Context Provider but unable to check network access on it using the window.navigator. It results to an error: "ReferenceError: window is not defined". Is there any way I can load the application first so I can use the custom modal dialog I created?

_app.js

function MyApp({ Component, pageProps }) {
  console.log(window)
  return <Component {...pageProps} />
}

export default MyApp

Error upon page reload:
Approach #1 Error

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

0

You can access window when component mounted by using useEffect:

function MyApp({ Component, pageProps }) {
 useEffect(() => {
        console.log(window)
 },[])
 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