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

213
Visualizações
How to call API once in _app and pass the data to the necessary children?

I'm currently converting my React.js project into Next.js.

I'm running into a few issues with props at the moment though.

Previously with React, I made API calls at app.js then passed it down into the navbar to be used in a search form.

With Next.js there's not really an option since API calls are blocked from the _app.js file. Which is where my layout.js (Nav/Footer).

options I'm considering:

  1. change the convention of the index.js file to be like the app.js instead of the home.js page.
  2. wrapping the layout on every page instead of wrapping _app.js and calling stock API on every page.

I feel like there's a better way to just call the API once and pass it to the necessary children. If someone can give me any recommendation on how to combat top-level sharing of props that would be great!

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

0

Consider doing the following

1.If the props are needed pervasively in the app eg. theme or auth object, create a Context provider and wrap the _app.js component with it.

2.If the props are needed in only few components, find the closest common ancestor and make the fetch there like you would normally do in React. additionally, in Nextjs, you can use getServerSideProps to pre-render pages on every request

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