Skip to content

Commit ca2df0f

Browse files
committed
Fix stale state of navigation in useRootNavigationState
1 parent d5c95c1 commit ca2df0f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/hooks/useRootNavigationState.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ function useRootNavigationState<T>(selector: Selector<T>): T {
2020
});
2121

2222
useEffect(() => {
23-
const unsubscribe = navigationRef.addListener('state', (e) => {
24-
setResult(selectorRef.current(e.data.state as NavigationState));
23+
const unsubscribe = navigationRef.addListener('state', () => {
24+
// State from the event data may be incomplete. (defined params but no nested state for the route)
25+
setResult(selectorRef.current(navigationRef.getRootState()));
2526
});
2627

2728
return unsubscribe;

0 commit comments

Comments
 (0)