react-native-onyx 3.0.42 → 3.0.44
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 +7 -1
- package/package.json +1 -1
package/dist/useOnyx.js
CHANGED
|
@@ -164,6 +164,10 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
164
164
|
OnyxConnectionManager_1.default.addToEvictionBlockList(connectionRef.current);
|
|
165
165
|
}
|
|
166
166
|
}, [key, options === null || options === void 0 ? void 0 : options.canEvict]);
|
|
167
|
+
// Tracks the last memoizedSelector reference that getSnapshot() has computed with.
|
|
168
|
+
// When the selector changes, this mismatch forces getSnapshot() to re-evaluate
|
|
169
|
+
// even if all other conditions (isFirstConnection, shouldGetCachedValue, key) are false.
|
|
170
|
+
const lastComputedSelectorRef = (0, react_1.useRef)(memoizedSelector);
|
|
167
171
|
const getSnapshot = (0, react_1.useCallback)(() => {
|
|
168
172
|
var _a, _b, _c, _d;
|
|
169
173
|
// Check if we have any cache for this Onyx key
|
|
@@ -186,10 +190,12 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
186
190
|
// We get the value from cache while the first connection to Onyx is being made or if the key has changed,
|
|
187
191
|
// so we can return any cached value right away. For the case where the key has changed, If we don't return the cached value right away, then the UI will show the incorrect (previous) value for a brief period which looks like a UI glitch to the user. After the connection is made, we only
|
|
188
192
|
// update `newValueRef` when `Onyx.connect()` callback is fired.
|
|
189
|
-
|
|
193
|
+
const hasSelectorChanged = lastComputedSelectorRef.current !== memoizedSelector;
|
|
194
|
+
if (isFirstConnectionRef.current || shouldGetCachedValueRef.current || key !== previousKey || hasSelectorChanged) {
|
|
190
195
|
// Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility.
|
|
191
196
|
const value = OnyxUtils_1.default.tryGetCachedValue(key);
|
|
192
197
|
const selectedValue = memoizedSelector ? memoizedSelector(value) : value;
|
|
198
|
+
lastComputedSelectorRef.current = memoizedSelector;
|
|
193
199
|
newValueRef.current = (selectedValue !== null && selectedValue !== void 0 ? selectedValue : undefined);
|
|
194
200
|
// We set this flag to `false` again since we don't want to get the newest cached value every time `getSnapshot()` is executed,
|
|
195
201
|
// and only when `Onyx.connect()` callback is fired.
|