react-native-onyx 2.0.88 → 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/Onyx.js CHANGED
@@ -500,8 +500,8 @@ function updateSnapshots(data) {
500
500
  if (!snapshotData || !snapshotData[key]) {
501
501
  return;
502
502
  }
503
- if (Array.isArray(value)) {
504
- updatedData[key] = value;
503
+ if (Array.isArray(value) || Array.isArray(snapshotData[key])) {
504
+ updatedData[key] = value || [];
505
505
  return;
506
506
  }
507
507
  const oldValue = updatedData[key] || {};
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.88",
3
+ "version": "2.0.90",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",