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

174
Views
How to use React hook that returns circular JSON as a dependent query for multiple React Query calls?

I have a library that exposes a React hook - usePlayground. This can only be called within the context of a function, and, when called, returns and object like this:

// object with circular references
const playground = {
  getUserDetails: () => new Promise({userId: '1234'}),
  apiKey: '1234',
}

I have a component, UserDetails that looks like this.

UserDetails.jsx

import {usePlayground} from 'my-providers';

function useUserData() {
  const playground = usePlayground();

  const userData = fetchUserData(playground);

  return [{
    apiKey: userData.apiKey,
    userId: userData.userId
  }]
}

function UserDetails() {
  const [{userId, apiKey}] = useUserData();

  const [{licenses}] = useLicenses(userId, apiKey);
  const [{todos}] = useTodos(userId, apiKey)

  return <div></div>
}

I have a react query service that should calculate the user ID and apiKey to pass to the consumer. I get a JSON circular reference detected from my devtools. I've also read that you aren't supposed to use an object like this as an argument to React query.

user-service.js

async function fetchUser(playground) {
  const userDetails = await playground.getUserDetails()
  return {
    apiKey: userDetails.apiKey,
    userId: userDetails.userId
  };
}

// this throws an error because playground object has circular references
export async function fetchUserData(playground) {
  return useQuery(['user', playground], fetchUser);
}

I would like to compute the apiKey and the userId once and access automatically in all of my react query hooks using dependent queries, but I am gettin the "JSON circular reference" error. How can I compute apiKey and userId once and use repeatedly in React query calls?

about 4 years ago · Juan Pablo Isaza
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!