Home > Mobile >  How to use UseQuery with useEffect?
How to use UseQuery with useEffect?

Time:12-11

How to use UseQuery in React.UseEffect? this is my simple query

  const {allrecord} = useQuery(ME, {
    onCompleted: ({ meTeacher}) => {
      setUser(meIAM);
      getRecords({
        variables: {
          orgId: meIAM.organization.id,
          pagingArg: {},
        },
      }).then(({ data }) => displayRecord(data.record));
    },
  });
  useEffect(() => {
    console.log(allLocations)
  }, []);

CodePudding user response:

useQuery is a hook and as such cannot be used under a branch.

This means that you must call useQuery inside your component and not under a branch statement (if/else/switch/useEffect).

If you need to do something with the result of a useQuery just use a useEffect with a dependency on that results

  • Related