Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

setParams entity change when is called #53

Closed
neiker opened this issue Nov 29, 2019 · 1 comment
Closed

setParams entity change when is called #53

neiker opened this issue Nov 29, 2019 · 1 comment

Comments

@neiker
Copy link

neiker commented Nov 29, 2019

This generates a loop when is used on useEffect

const { setParams } = useNavigation();

const { error, data, refetch } = Apollo.useQuery<GetCardsResponse>(GET_CARDS);

useEffect(() => {
    if (data) {
      setParams({ showTitle: data.cards.length > 0 });
    }
  }, [data, setParams]);

Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate.

This works:

useEffect(() => {
    if (data) {
      setParams({ showTitle: data.cards.length > 0 });
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [data]);
@slorber
Copy link
Member

slorber commented Nov 30, 2019

Hi
It's the same issue as #40

@slorber slorber closed this as completed Nov 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants