Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda