score:0

Accepted answer

You are breaking the rule of hooks when you call it from any place other than the top level of a React component.

useEffect takes a callback function, and you are calling your hook from that. It is a problem.

I found this skip option in useQuery which helps you call useQuery conditionally.

 useEffect(() => {
    const { loading, error, data } = 
    useQuery(GET_MORTGAGE_JOURNEY, {
      variables: { id: insuranceId },
      skip : (!insuranceId)
    });
  }, [insuranceId]);

Any time insuranceId changes your callback runs, so it is run after mount once and then on subsequent changes.


Related Query

More Query from same tag