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

88
Visualizações
Next JS How to pass state to getStaticProps

I am fetching games from IGDB database using getStaticProps. Everything works fine but now I want to implement searching games using text input and button. I am getting value from text input using onChange and I need to pass the state to the search query, but how I can do this outside the function? Here is the code:

export async function getStaticProps() {
    const response = await fetch(
        `https://api.igdb.com/v4/games/?fields=cover.*,name;search=${HERE I NEED TO PASS INPUT VALUE};`,
          {
            headers: {
                'Accept': 'application/json',
                'Client-ID': 'my client_id',
                'Authorization': 'Bearer my_authorization',
            }
        })
    const data = await response.json()
    return {
        props: {
            apiGames: data
        }
    }
}

const Library = ({ apiGames }) => {

  const [inputValue, setInputValue] = useState('')

  return (
    <input type="text" onChange={(e) => setInputValue(e.target.value)} placeholder='Start searching game...' />
  )
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

getStaticProps only runs at build time. You can fetch your initial data using this approach, but since your search params are generated on the client side, you will need to fetch your data on the client also. You can use the fetch api, or a library like axios

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