Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!