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

295
Vistas
Multiple Apollo queries in one component, getting cannot redeclare block-scoped variable

I have these two Apollo queries in one React component:

 const { data, loading, error } = useQuery(PlaylistQuery, {
    variables: { _id: playlistId },
    fetchPolicy: "cache-and-network",
  });

  const [loadSong, { called, loading, error, data }] = useLazyQuery(SongQuery, {
    variables: {
      _id: song._id,
    },
  });

This will obviously give me this error message:

Cannot redeclare block-scoped variable

What's a smart way to get around this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To avoid this issue, you could simply name your queries' variables. As an example like below:

const { data: playListData, loading: playListLoading, error: playListError } = useQuery(PlaylistQuery, {
    variables: { _id: playlistId },
    fetchPolicy: "cache-and-network",
  });

  const [loadSong, { called: songFuctionCalled, loading: songLoading, error: songError, data :songData }] = useLazyQuery(SongQuery, {
    variables: {
      _id: song._id,
    },
  });
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