@react-navigation/core 7.0.4 → 7.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/useNavigationBuilder.js +3 -5
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +1 -1
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +14 -3
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +3 -5
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +1 -1
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +14 -3
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts +3 -1
- package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/module/src/useNavigationHelpers.d.ts +3 -1
- package/lib/typescript/module/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/useNavigationBuilder.tsx +2 -5
- package/src/useNavigationCache.tsx +1 -1
- package/src/useNavigationHelpers.tsx +18 -4
|
@@ -21,6 +21,7 @@ type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|
|
21
21
|
getState: () => State;
|
|
22
22
|
emitter: NavigationEventEmitter<any>;
|
|
23
23
|
router: Router<State, Action>;
|
|
24
|
+
stateRef: React.RefObject<State | null>;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -38,6 +39,7 @@ export function useNavigationHelpers<
|
|
|
38
39
|
getState,
|
|
39
40
|
emitter,
|
|
40
41
|
router,
|
|
42
|
+
stateRef,
|
|
41
43
|
}: Options<State, Action>) {
|
|
42
44
|
const onUnhandledAction = React.useContext(UnhandledActionContext);
|
|
43
45
|
const parentNavigationHelpers = React.useContext(NavigationContext);
|
|
@@ -99,17 +101,29 @@ export function useNavigationHelpers<
|
|
|
99
101
|
|
|
100
102
|
return parentNavigationHelpers;
|
|
101
103
|
},
|
|
102
|
-
getState
|
|
104
|
+
getState: (): State => {
|
|
105
|
+
// FIXME: Workaround for when the state is read during render
|
|
106
|
+
// By this time, we haven't committed the new state yet
|
|
107
|
+
// Without this `useSyncExternalStore` will keep reading the old state
|
|
108
|
+
// This may result in `useNavigationState` or `useIsFocused` returning wrong values
|
|
109
|
+
// Apart from `useSyncExternalStore`, `getState` should never be called during render
|
|
110
|
+
if (stateRef.current != null) {
|
|
111
|
+
return stateRef.current;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return getState();
|
|
115
|
+
},
|
|
103
116
|
} as NavigationHelpers<ParamListBase, EventMap> & ActionHelpers;
|
|
104
117
|
|
|
105
118
|
return navigationHelpers;
|
|
106
119
|
}, [
|
|
107
|
-
|
|
120
|
+
router,
|
|
121
|
+
parentNavigationHelpers,
|
|
108
122
|
emitter.emit,
|
|
109
123
|
getState,
|
|
110
124
|
onAction,
|
|
111
125
|
onUnhandledAction,
|
|
112
|
-
|
|
113
|
-
|
|
126
|
+
navigatorId,
|
|
127
|
+
stateRef,
|
|
114
128
|
]);
|
|
115
129
|
}
|