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

176
Vistas
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
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