-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Related to this hooks issue: react-navigation/hooks#3 (comment)
People are trying to use the navigate() function in useEffect, and try to comply to eslint dependency rules, unfortunately the navigation function provided by the NavigationContext changes often, and lead to unwanted effect re-executions on each screen change.
function ReactComponent() {
const {navigate} = useNavigation();
useEffect(() => {
if (user) {
navigate(...)
}
}, [user, navigate])
return null
}
Not sure exactly how to fix this, but it would be nice if the navigation actions would be memoized to avoid being recreated.
Could it make sense to cache per route key the result of getNavigationActionCreators / router.getActionCreators ?
https://github.com/react-navigation/core/blob/e514a61f9314e8d771231de9d3a4ebf64f661003/src/getNavigation.js#L46
https://github.com/react-navigation/core/blob/e514a61f9314e8d771231de9d3a4ebf64f661003/src/routers/getNavigationActionCreators.js