react-native-onyx 3.0.23 → 3.0.24
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/dist/useOnyx.js +10 -0
- package/package.json +1 -1
package/dist/useOnyx.js
CHANGED
|
@@ -86,6 +86,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
86
86
|
const previousValueRef = (0, react_1.useRef)(null);
|
|
87
87
|
// Stores the newest cached value in order to compare with the previous one and optimize `getSnapshot()` execution.
|
|
88
88
|
const newValueRef = (0, react_1.useRef)(null);
|
|
89
|
+
const lastConnectedKeyRef = (0, react_1.useRef)(key);
|
|
89
90
|
// Stores the previously result returned by the hook, containing the data from cache and the fetch status.
|
|
90
91
|
// We initialize it to `undefined` and `loading` fetch status to simulate the initial result when the hook is loading from the cache.
|
|
91
92
|
// However, if `initWithStoredValues` is `false` we set the fetch status to `loaded` since we want to signal that data is ready.
|
|
@@ -114,6 +115,15 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
114
115
|
canBeMissing: options === null || options === void 0 ? void 0 : options.canBeMissing,
|
|
115
116
|
}), [options === null || options === void 0 ? void 0 : options.selector, options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing]);
|
|
116
117
|
(0, react_1.useEffect)(() => () => OnyxSnapshotCache_1.default.deregisterConsumer(key, cacheKey), [key, cacheKey]);
|
|
118
|
+
(0, react_1.useEffect)(() => {
|
|
119
|
+
if (lastConnectedKeyRef.current === key) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
lastConnectedKeyRef.current = key;
|
|
123
|
+
shouldGetCachedValueRef.current = true;
|
|
124
|
+
previousValueRef.current = null;
|
|
125
|
+
resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
|
|
126
|
+
}, [key, options === null || options === void 0 ? void 0 : options.initWithStoredValues]);
|
|
117
127
|
(0, react_1.useEffect)(() => {
|
|
118
128
|
// These conditions will ensure we can only handle dynamic collection member keys from the same collection.
|
|
119
129
|
if ((options === null || options === void 0 ? void 0 : options.allowDynamicKey) || previousKey === key) {
|