hooks icon indicating copy to clipboard operation
hooks copied to clipboard

Provide stable navigation actions

Open slorber opened this issue 6 years ago • 2 comments

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: https://github.com/react-navigation/hooks/issues/3#issuecomment-524176110)

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 avatar Sep 06 '19 11:09 slorber

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

https://github.com/facebook/react/issues/16956

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

slorber avatar Sep 30 '19 11:09 slorber

@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

cmmartin avatar Oct 04 '19 22:10 cmmartin