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

117
Views
Avoid multiple network calls with hooks and Apollo

I have a hook that makes an Graphql call

export const useGetStuff = (options?: QueryHookOptions<GetStuffResponse, GetStuffQueryArgs>) => {
    const [stuffId] = useStuffId();

    return useQuery<GetStuffResponse, GetStuffQueryArgs>(getStuff, {
        variables: { stuffId },
        notifyOnNetworkStatusChange: true,
        skip: !stuffId,
        ssr: false,
        ...options,
    });
};

And I am using this hook in one another hook

const useCustomHook = () => {
    // some unrelated stuff
    const { data: stuffData, loading } = useGetStuff();
   
    // do logic with stuffData and other unrelated stuff

    return { someProperty };
    
}

and in some component, I am using both useGetStuff and useCustomHook.

const MyComponent = () => {
    const { someProperty } = useCustomHook();
    const { data ,loading } = useGetStuff();

    // stuff
    
}

This implementation causes the getStuff query to be called twice (two network calls).

Is there a simple way to avoid that without having to keep useGetStuff only in the custom hook, since this latter should not have to be returning the stuffData.

about 4 years ago · Santiago Trujillo
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!