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

Provide stable navigation actions #40

Open
slorber opened this issue Sep 6, 2019 · 2 comments
Open

Provide stable navigation actions #40

slorber opened this issue Sep 6, 2019 · 2 comments

Comments

@slorber
Copy link
Member

slorber commented Sep 6, 2019

function ReactComponent() {
  const { navigate } = useNavigation();
  useEffect(() => {
      if (someBoolean) {
          navigate(...)
      }
  },  [someBoolean,navigate])
}

The functions like navigate/goBack etc should be able to be used in hooks / dependency arrays.

We should rather make them stable so that they don't trigger effect re-execution on every navigate action, which is not the case currently (as reported by @cmmartin here: #3 (comment))

See also https://github.com/react-navigation/core/issues/71

The core does not provide stable action functions currently, and it may be complicated to do so and guarantee that as part of the core contract.

But we can provide stabilization in this package.

@slorber
Copy link
Member Author

slorber commented Sep 30, 2019

@cmmartin for the record I've opened a React issue, which is a bit related to this issue (at least it's an example).

facebook/react#16956

Will try to see which solution to adopt after having answers.

@cmmartin
Copy link

cmmartin commented Oct 4, 2019

@slorber Thanks for writing that up. I have been struggling with the same issues. My codebase is full of violations of the hooks dependencies lint rule and I'm not sure how to resolve them. Will follow the other issue

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