Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change useLayoutEffect of useNavigationComponentHooks to useEffect #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hancandice
Copy link

@hancandice hancandice commented Jun 14, 2022

I changed useLayoutEffect to useEffect at useNavigationComponentDidAppear & useNavigationComponentDidDisppear.

const useNavigationComponentDidAppear = (
  handler: EventHandler,
  componentId: string
) => {
  useLayoutEffect(() => {
    const subscription = Navigation.events().registerComponentDidAppearListener(
      (event: ComponentDidAppearEvent) =>
        triggerIfComponentIdMatches(handler, event, componentId)
    );
    return () => subscription.remove();
  }, [handler, componentId]);
};

As you can see, in previous code, useNavigationComponentDidAppear worked by using useLayoutEffect to registerComponentDidAppearListener to navigation events. (The signature of useNavigationComponentDidDisppear is the same)

So if user use setState inside useNavigationComponentDidAppear, the next call will not be called because the component will be updated before the next effect is executed.

That's why some user experiences this issue : #62

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant