Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda