react-native-onyx 2.0.89 → 2.0.90
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.d.ts +6 -1
- package/dist/useOnyx.js +2 -2
- package/package.json +1 -1
package/dist/useOnyx.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ type BaseUseOnyxOptions = {
|
|
|
18
18
|
* with the same connect configurations.
|
|
19
19
|
*/
|
|
20
20
|
reuseConnection?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If set to `true`, the key can be changed dynamically during the component lifecycle.
|
|
23
|
+
*/
|
|
24
|
+
allowDynamicKey?: boolean;
|
|
21
25
|
};
|
|
22
26
|
type UseOnyxInitialValueOption<TInitialValue> = {
|
|
23
27
|
/**
|
|
@@ -36,6 +40,7 @@ type UseOnyxSelectorOption<TKey extends OnyxKey, TReturnValue> = {
|
|
|
36
40
|
*/
|
|
37
41
|
selector?: UseOnyxSelector<TKey, TReturnValue>;
|
|
38
42
|
};
|
|
43
|
+
type UseOnyxOptions<TKey extends OnyxKey, TReturnValue> = BaseUseOnyxOptions & UseOnyxInitialValueOption<TReturnValue> & UseOnyxSelectorOption<TKey, TReturnValue>;
|
|
39
44
|
type FetchStatus = 'loading' | 'loaded';
|
|
40
45
|
type ResultMetadata = {
|
|
41
46
|
status: FetchStatus;
|
|
@@ -44,4 +49,4 @@ type UseOnyxResult<TValue> = [NonNullable<TValue> | undefined, ResultMetadata];
|
|
|
44
49
|
declare function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey, options?: BaseUseOnyxOptions & UseOnyxInitialValueOption<TReturnValue> & Required<UseOnyxSelectorOption<TKey, TReturnValue>>, dependencies?: DependencyList): UseOnyxResult<TReturnValue>;
|
|
45
50
|
declare function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey, options?: BaseUseOnyxOptions & UseOnyxInitialValueOption<NoInfer<TReturnValue>>, dependencies?: DependencyList): UseOnyxResult<TReturnValue>;
|
|
46
51
|
export default useOnyx;
|
|
47
|
-
export type { FetchStatus, ResultMetadata, UseOnyxResult };
|
|
52
|
+
export type { FetchStatus, ResultMetadata, UseOnyxResult, BaseUseOnyxOptions, UseOnyxSelector, UseOnyxSelectorOption, UseOnyxInitialValueOption, UseOnyxOptions };
|
package/dist/useOnyx.js
CHANGED
|
@@ -96,7 +96,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
96
96
|
const shouldGetCachedValueRef = (0, react_1.useRef)(true);
|
|
97
97
|
(0, react_1.useEffect)(() => {
|
|
98
98
|
// These conditions will ensure we can only handle dynamic collection member keys from the same collection.
|
|
99
|
-
if (previousKey === key) {
|
|
99
|
+
if ((options === null || options === void 0 ? void 0 : options.allowDynamicKey) || previousKey === key) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
try {
|
|
@@ -112,7 +112,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
112
112
|
throw new Error(`'${previousKey}' key can't be changed to '${key}'. useOnyx() only supports dynamic keys if they are both collection member keys from the same collection e.g. from 'collection_id1' to 'collection_id2'.`);
|
|
113
113
|
}
|
|
114
114
|
throw new Error(`'${previousKey}' key can't be changed to '${key}'. useOnyx() only supports dynamic keys if they are both collection member keys from the same collection e.g. from 'collection_id1' to 'collection_id2'.`);
|
|
115
|
-
}, [previousKey, key]);
|
|
115
|
+
}, [previousKey, key, options === null || options === void 0 ? void 0 : options.allowDynamicKey]);
|
|
116
116
|
(0, react_1.useEffect)(() => {
|
|
117
117
|
// This effect will only run if the `dependencies` array changes. If it changes it will force the hook
|
|
118
118
|
// to trigger a `getSnapshot()` update by calling the stored `onStoreChange()` function reference, thus
|