admin管理员组

文章数量:1405636

I have below code snippet:

const [state, setState] = useState(null);

{data, loading, error} = useQuery(SOME_QUERY, {fetchPolicy: 'no-cache'});

useEffect(() => {
  setState(data)
}, [data]);

This seems to only render twice, once for the first render, and second once the GQL call is completed. My doubt is why is this not leading to infinite re-renders?

Component render -> useQuery fires -> call completed -> state updated by useEffect -> another render happens -> useQuery again fires and so on.

Is useQuery internally managing all of this? I also see only one network call being made.

本文标签: reactjsuseQuery with useEffect not causing infinite rerenderStack Overflow