react-native-onyx 2.0.43 → 2.0.45

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/README.md CHANGED
@@ -9,7 +9,7 @@ Awesome persistent storage solution wrapped in a Pub/Sub library.
9
9
  - Onyx allows other code to subscribe to changes in data, and then publishes change events whenever data is changed
10
10
  - Anything needing to read Onyx data needs to:
11
11
  1. Know what key the data is stored in (for web, you can find this by looking in the JS console > Application > local storage)
12
- 2. Subscribe to changes of the data for a particular key or set of keys. React components use `withOnyx()` and non-React libs use `Onyx.connect()`.
12
+ 2. Subscribe to changes of the data for a particular key or set of keys. React function components use the `useOnyx()` hook (recommended), both class and function components can use `withOnyx()` HOC (deprecated, not-recommended) and non-React libs use `Onyx.connect()`.
13
13
  3. Get initialized with the current value of that key from persistent storage (Onyx does this by calling `setState()` or triggering the `callback` with the values currently on disk as part of the connection process)
14
14
  - Subscribing to Onyx keys is done using a constant defined in `ONYXKEYS`. Each Onyx key represents either a collection of items or a specific entry in storage. For example, since all reports are stored as individual keys like `report_1234`, if code needs to know about all the reports (e.g. display a list of them in the nav menu), then it would subscribe to the key `ONYXKEYS.COLLECTION.REPORT`.
15
15
 
@@ -116,7 +116,41 @@ To teardown the subscription call `Onyx.disconnect()` with the `connectionID` re
116
116
  Onyx.disconnect(connectionID);
117
117
  ```
118
118
 
119
- We can also access values inside React components via the `withOnyx()` [higher order component](https://reactjs.org/docs/higher-order-components.html). When the data changes the component will re-render.
119
+ We can also access values inside React function components via the `useOnyx()` [hook](https://react.dev/reference/react/hooks) (recommended) or class and function components via the `withOnyx()` [higher order component](https://reactjs.org/docs/higher-order-components.html) (deprecated, not-recommended). When the data changes the component will re-render.
120
+
121
+ ```javascript
122
+ import React from 'react';
123
+ import {useOnyx} from 'react-native-onyx';
124
+
125
+ const App = () => {
126
+ const [session] = useOnyx('session');
127
+
128
+ return (
129
+ <View>
130
+ {session.token ? <Text>Logged in</Text> : <Text>Logged out</Text>}
131
+ </View>
132
+ );
133
+ };
134
+
135
+ export default App;
136
+ ```
137
+
138
+ The `useOnyx()` hook won't delay the rendering of the component using it while the key/entity is being fetched and passed to the component. However, you can simulate this behavior by checking if the `status` of the hook's result metadata is `loading`. When `status` is `loading` it means that the Onyx data is being loaded into cache and thus is not immediately available, while `loaded` means that the data is already loaded and available to be consumed.
139
+
140
+ ```javascript
141
+ const [reports, reportsResult] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
142
+ const [session, sessionResult] = useOnyx(ONYXKEYS.SESSION);
143
+
144
+ if (reportsResult.status === 'loading' || sessionResult.status === 'loading') {
145
+ return <Placeholder />; // or `null` if you don't want to render anything.
146
+ }
147
+
148
+ // rest of the component's code.
149
+ ```
150
+
151
+ > [!warning]
152
+ > ## Deprecated Note
153
+ > Please note that the `withOnyx()` Higher Order Component (HOC) is now considered deprecated. Use `useOnyx()` hook instead.
120
154
 
121
155
  ```javascript
122
156
  import React from 'react';
@@ -135,7 +169,7 @@ export default withOnyx({
135
169
  })(App);
136
170
  ```
137
171
 
138
- While `Onyx.connect()` gives you more control on how your component reacts as data is fetched from disk, `withOnyx()` will delay the rendering of the wrapped component until all keys/entities have been fetched and passed to the component, this can be convenient for simple cases. This however, can really delay your application if many entities are connected to the same component, you can pass an `initialValue` to each key to allow Onyx to eagerly render your component with this value.
172
+ Differently from `useOnyx()`, `withOnyx()` will delay the rendering of the wrapped component until all keys/entities have been fetched and passed to the component, this can be convenient for simple cases. This however, can really delay your application if many entities are connected to the same component, you can pass an `initialValue` to each key to allow Onyx to eagerly render your component with this value.
139
173
 
140
174
  ```javascript
141
175
  export default withOnyx({
@@ -146,7 +180,9 @@ export default withOnyx({
146
180
  })(App);
147
181
  ```
148
182
 
149
- Additionally, if your component has many keys/entities when your component will mount but will receive many updates as data is fetched from DB and passed down to it, as every key that gets fetched will trigger a `setState` on the `withOnyx` HOC. This might cause re-renders on the initial mounting, preventing the component from mounting/rendering in reasonable time, making your app feel slow and even delaying animations. You can workaround this by passing an additional object with the `shouldDelayUpdates` property set to true. Onyx will then put all the updates in a queue until you decide when then should be applied, the component will receive a function `markReadyForHydration`. A good place to call this function is on the `onLayout` method, which gets triggered after your component has been rendered.
183
+ Additionally, if your component has many keys/entities when your component will mount but will receive many updates as data is fetched from DB and passed down to it, as every key that gets fetched will trigger a `setState` on the `withOnyx` HOC. This might cause re-renders on the initial mounting, preventing the component from mounting/rendering in reasonable time, making your app feel slow and even delaying animations.
184
+
185
+ You can workaround this by passing an additional object with the `shouldDelayUpdates` property set to true. Onyx will then put all the updates in a queue until you decide when then should be applied, the component will receive a function `markReadyForHydration`. A good place to call this function is on the `onLayout` method, which gets triggered after your component has been rendered.
150
186
 
151
187
  ```javascript
152
188
  const App = ({session, markReadyForHydration}) => (
@@ -164,27 +200,43 @@ export default withOnyx({
164
200
  }, true)(App);
165
201
  ```
166
202
 
167
- ### Dependent Onyx Keys and withOnyx()
203
+ ### Dependent Onyx Keys and useOnyx()
168
204
  Some components need to subscribe to multiple Onyx keys at once and sometimes, one key might rely on the data from another key. This is similar to a JOIN in SQL.
169
205
 
170
206
  Example: To get the policy of a report, the `policy` key depends on the `report` key.
171
207
 
172
208
  ```javascript
173
- export default withOnyx({
174
- report: {
175
- key: ({reportID) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
176
- },
177
- policy: {
178
- key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
179
- },
180
- })(App);
209
+ const App = ({reportID}) => {
210
+ const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
211
+ const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`);
212
+
213
+ return (
214
+ <View>
215
+ {/* Render with policy data */}
216
+ </View>
217
+ );
218
+ };
219
+
220
+ export default App;
181
221
  ```
182
222
 
183
- Background info:
184
- - The `key` value can be a function that returns the key that Onyx subscribes to
185
- - The first argument to the `key` function is the `props` from the component
223
+ **Detailed explanation of how this is handled and rendered with `useOnyx()`:**
224
+
225
+ 1. The component mounts with a `reportID={1234}` prop.
226
+ 2. The `useOnyx` hook evaluates the mapping and subscribes to the key `reports_1234` using the `reportID` prop.
227
+ 3. The `useOnyx` hook fetches the data for the key `reports_1234` from Onyx and sets the state with the initial value (if provided).
228
+ 4. Since `report` is not defined yet, `report?.policyID` defaults to `undefined`. The `useOnyx` hook subscribes to the key `policies_undefined`.
229
+ 5. The `useOnyx` hook reads the data and updates the state of the component:
230
+ - `report={{reportID: 1234, policyID: 1, ...rest of the object...}}`
231
+ - `policy={undefined}` (since there is no policy with ID `undefined`)
232
+ 6. The `useOnyx` hook again evaluates the key `policies_1` after fetching the updated `report` object which has `policyID: 1`.
233
+ 7. The `useOnyx` hook reads the data and updates the state with:
234
+ - `policy={{policyID: 1, ...rest of the object...}}`
235
+ 8. Now, all mappings have values that are defined (not undefined), and the component is rendered with all necessary data.
236
+
237
+ * It is VERY important to NOT use empty string default values like `report.policyID || ''`. This results in the key returned to `useOnyx` as `policies_`, which subscribes to the ENTIRE POLICY COLLECTION and is most assuredly not what you were intending. You can use a default of `0` (as long as you are reasonably sure that there is never a policyID=0). This allows Onyx to return `undefined` as the value of the policy key, which is handled by `useOnyx` appropriately.
186
238
 
187
- **Detailed explanation of how this is handled and rendered:**
239
+ **Detailed explanation of how this is handled and rendered with `withOnyx` HOC:**
188
240
  1. The component mounts with a `reportID={1234}` prop
189
241
  2. `withOnyx` evaluates the mapping
190
242
  3. `withOnyx` connects to the key `reports_1234` because of the prop passed to the component
@@ -239,15 +291,23 @@ Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
239
291
  There are several ways to subscribe to these keys:
240
292
 
241
293
  ```javascript
242
- withOnyx({
243
- allReports: {key: ONYXKEYS.COLLECTION.REPORT},
244
- })(MyComponent);
294
+ const MyComponent = () => {
295
+ const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
296
+
297
+ return (
298
+ <View>
299
+ {/* Render with allReports data */}
300
+ </View>
301
+ );
302
+ };
303
+
304
+ export default MyComponent;
245
305
  ```
246
306
 
247
307
  This will add a prop to the component called `allReports` which is an object of collection member key/values. Changes to the individual member keys will modify the entire object and new props will be passed with each individual key update. The prop doesn't update on the initial rendering of the component until the entire collection has been read out of Onyx.
248
308
 
249
309
  ```js
250
- Onyx.connect({key: ONYXKEYS.COLLECTION.REPORT}, callback: (memberValue, memberKey) => {...}});
310
+ Onyx.connect({key: ONYXKEYS.COLLECTION.REPORT}, callback: (memberValue, memberKey) => {...});
251
311
  ```
252
312
 
253
313
  This will fire the callback once per member key depending on how many collection member keys are currently stored. Changes to those keys after the initial callbacks fire will occur when each individual key is updated.
@@ -256,11 +316,11 @@ This will fire the callback once per member key depending on how many collection
256
316
  Onyx.connect({
257
317
  key: ONYXKEYS.COLLECTION.REPORT,
258
318
  waitForCollectionCallback: true,
259
- callback: (allReports) => {...}},
319
+ callback: (allReports) => {...},
260
320
  });
261
321
  ```
262
322
 
263
- This final option forces `Onyx.connect()` to behave more like `withOnyx()` and only update the callback once with the entire collection initially and later with an updated version of the collection when individual keys update.
323
+ This final option forces `Onyx.connect()` to behave more like `useOnyx()` and only update the callback once with the entire collection initially and later with an updated version of the collection when individual keys update.
264
324
 
265
325
  ### Performance Considerations When Using Collections
266
326
 
@@ -270,12 +330,12 @@ Remember, `mergeCollection()` will notify a subscriber only *once* with the tota
270
330
 
271
331
  ```js
272
332
  // Bad
273
- _.each(reports, report => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report)); // -> A component using withOnyx() will have it's state updated with each iteration
333
+ _.each(reports, report => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report)); // -> A component using useOnyx() will have it's state updated with each iteration
274
334
 
275
335
  // Good
276
336
  const values = {};
277
337
  _.each(reports, report => values[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] = report);
278
- Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, values); // -> A component using withOnyx() will only have it's state updated once
338
+ Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, values); // -> A component using useOnyx() will only have its state updated once
279
339
  ```
280
340
 
281
341
  ## Clean up
@@ -325,12 +385,20 @@ Onyx.init({
325
385
  ```
326
386
 
327
387
  ```js
328
- export default withOnyx({
329
- reportActions: {
330
- key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}_`,
331
- canEvict: props => !props.isActiveReport,
332
- },
333
- })(ReportActionsView);
388
+ const ReportActionsView = ({reportID, isActiveReport}) => {
389
+ const [reportActions] = useOnyx(
390
+ `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}_`,
391
+ {canEvict: () => !isActiveReport}
392
+ );
393
+
394
+ return (
395
+ <View>
396
+ {/* Render with reportActions data */}
397
+ </View>
398
+ );
399
+ };
400
+
401
+ export default ReportActionsView;
334
402
  ```
335
403
 
336
404
  # Benchmarks
package/dist/Onyx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Logger from './Logger';
2
- import type { Collection, CollectionKeyBase, ConnectOptions, InitOptions, KeyValueMapping, Mapping, NonUndefined, NullableKeyValueMapping, NullishDeep, OnyxEntry, OnyxKey, OnyxUpdate } from './types';
2
+ import type { CollectionKeyBase, ConnectOptions, InitOptions, Mapping, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate } from './types';
3
3
  /** Initialize the store with actions and listening for storage events */
4
4
  declare function init({ keys, initialKeyStates, safeEvictionKeys, maxCachedKeysCount, shouldSyncMultipleInstances, debugSetState, }: InitOptions): void;
5
5
  /**
@@ -45,7 +45,7 @@ declare function disconnect(connectionID: number, keyToRemoveFromEvictionBlockli
45
45
  * @param key ONYXKEY to set
46
46
  * @param value value to store
47
47
  */
48
- declare function set<TKey extends OnyxKey>(key: TKey, value: NonUndefined<OnyxEntry<KeyValueMapping[TKey]>>): Promise<void>;
48
+ declare function set<TKey extends OnyxKey>(key: TKey, value: OnyxSetInput<TKey>): Promise<void>;
49
49
  /**
50
50
  * Sets multiple keys and values
51
51
  *
@@ -53,7 +53,7 @@ declare function set<TKey extends OnyxKey>(key: TKey, value: NonUndefined<OnyxEn
53
53
  *
54
54
  * @param data object keyed by ONYXKEYS and the values to set
55
55
  */
56
- declare function multiSet(data: Partial<NullableKeyValueMapping>): Promise<void>;
56
+ declare function multiSet(data: OnyxMultiSetInput): Promise<void>;
57
57
  /**
58
58
  * Merge a new value into an existing value at a key.
59
59
  *
@@ -70,7 +70,7 @@ declare function multiSet(data: Partial<NullableKeyValueMapping>): Promise<void>
70
70
  * Onyx.merge(ONYXKEYS.POLICY, {id: 1}); // -> {id: 1}
71
71
  * Onyx.merge(ONYXKEYS.POLICY, {name: 'My Workspace'}); // -> {id: 1, name: 'My Workspace'}
72
72
  */
73
- declare function merge<TKey extends OnyxKey>(key: TKey, changes: NonUndefined<OnyxEntry<NullishDeep<KeyValueMapping[TKey]>>>): Promise<void>;
73
+ declare function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxMergeInput<TKey>): Promise<void>;
74
74
  /**
75
75
  * Merges a collection based on their keys
76
76
  *
@@ -84,7 +84,7 @@ declare function merge<TKey extends OnyxKey>(key: TKey, changes: NonUndefined<On
84
84
  * @param collectionKey e.g. `ONYXKEYS.COLLECTION.REPORT`
85
85
  * @param collection Object collection keyed by individual collection member keys and values
86
86
  */
87
- declare function mergeCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: Collection<TKey, TMap, NullishDeep<KeyValueMapping[TKey]>>): Promise<void>;
87
+ declare function mergeCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TKey, collection: OnyxMergeCollectionInput<TKey, TMap>): Promise<void>;
88
88
  /**
89
89
  * Clear out all the data in the store
90
90
  *
@@ -1,6 +1,6 @@
1
1
  import type { ValueOf } from 'type-fest';
2
2
  import type Onyx from './Onyx';
3
- import type { CollectionKey, CollectionKeyBase, DeepRecord, KeyValueMapping, Mapping, NullableKeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, WithOnyxConnectOptions } from './types';
3
+ import type { CollectionKey, CollectionKeyBase, DeepRecord, KeyValueMapping, Mapping, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, WithOnyxConnectOptions } from './types';
4
4
  declare const METHOD: {
5
5
  readonly SET: "set";
6
6
  readonly MERGE: "merge";
@@ -32,7 +32,7 @@ declare function getDefaultKeyStates(): Record<OnyxKey, OnyxValue<OnyxKey>>;
32
32
  * @param initialKeyStates - initial data to set when `init()` and `clear()` are called
33
33
  * @param safeEvictionKeys - This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal.
34
34
  */
35
- declare function initStoreValues(keys: DeepRecord<string, OnyxKey>, initialKeyStates: Partial<NullableKeyValueMapping>, safeEvictionKeys: OnyxKey[]): void;
35
+ declare function initStoreValues(keys: DeepRecord<string, OnyxKey>, initialKeyStates: Partial<KeyValueMapping>, safeEvictionKeys: OnyxKey[]): void;
36
36
  /**
37
37
  * Sends an action to DevTools extension
38
38
  *
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { ConnectOptions, OnyxUpdate } from './Onyx';
2
2
  import Onyx from './Onyx';
3
- import type { CustomTypeOptions, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, Selector } from './types';
3
+ import type { CustomTypeOptions, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxValue, Selector, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput } from './types';
4
4
  import type { FetchStatus, ResultMetadata, UseOnyxResult } from './useOnyx';
5
5
  import useOnyx from './useOnyx';
6
6
  import withOnyx from './withOnyx';
7
7
  import type { WithOnyxState } from './withOnyx/types';
8
8
  export default Onyx;
9
9
  export { useOnyx, withOnyx };
10
- export type { ConnectOptions, CustomTypeOptions, FetchStatus, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxUpdate, OnyxValue, ResultMetadata, Selector, UseOnyxResult, WithOnyxState, };
10
+ export type { ConnectOptions, CustomTypeOptions, FetchStatus, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, ResultMetadata, Selector, UseOnyxResult, WithOnyxState, };
package/dist/types.d.ts CHANGED
@@ -121,7 +121,7 @@ type KeyValueMapping = {
121
121
  * It's very similar to `KeyValueMapping` but this type accepts using `null` as well.
122
122
  */
123
123
  type NullableKeyValueMapping = {
124
- [TKey in OnyxKey]: OnyxValue<TKey>;
124
+ [TKey in OnyxKey]: NonUndefined<OnyxValue<TKey>> | null;
125
125
  };
126
126
  /**
127
127
  * Represents a selector function type which operates based on the provided `TKey` and `ReturnType`.
@@ -162,6 +162,12 @@ type Selector<TKey extends OnyxKey, TOnyxProps, TReturnType> = (value: OnyxEntry
162
162
  * ```
163
163
  */
164
164
  type OnyxEntry<TOnyxValue> = TOnyxValue | undefined;
165
+ /**
166
+ * Represents an input value that can be passed to Onyx methods, that can be either `TOnyxValue` or `null`.
167
+ * Setting a key to `null` will remove the key from the store.
168
+ * `undefined` is not allowed for setting values, because it will have no effect on the data.
169
+ */
170
+ type OnyxInput<TOnyxValue> = TOnyxValue | null;
165
171
  /**
166
172
  * Represents an Onyx collection of entries, that can be either a record of `TOnyxValue`s or `null` / `undefined` if it is empty or doesn't exist.
167
173
  *
@@ -229,7 +235,7 @@ type NullishObjectDeep<ObjectType extends object> = {
229
235
  * Also, the `TMap` type is inferred automatically in `mergeCollection()` method and represents
230
236
  * the object of collection keys/values specified in the second parameter of the method.
231
237
  */
232
- type Collection<TKey extends CollectionKeyBase, TMap, TValue> = {
238
+ type Collection<TKey extends CollectionKeyBase, TValue, TMap = never> = {
233
239
  [MapK in keyof TMap]: MapK extends `${TKey}${string}` ? MapK extends `${TKey}` ? never : TValue : never;
234
240
  };
235
241
  /** Represents the base options used in `Onyx.connect()` method. */
@@ -276,6 +282,22 @@ type ConnectOptions<TKey extends OnyxKey> = (CollectionConnectOptions<TKey> | De
276
282
  type Mapping<TKey extends OnyxKey> = ConnectOptions<TKey> & {
277
283
  connectionID: number;
278
284
  };
285
+ /**
286
+ * This represents the value that can be passed to `Onyx.set` and to `Onyx.update` with the method "SET"
287
+ */
288
+ type OnyxSetInput<TKey extends OnyxKey> = OnyxInput<KeyValueMapping[TKey]>;
289
+ /**
290
+ * This represents the value that can be passed to `Onyx.multiSet` and to `Onyx.update` with the method "MULTI_SET"
291
+ */
292
+ type OnyxMultiSetInput = Partial<NullableKeyValueMapping>;
293
+ /**
294
+ * This represents the value that can be passed to `Onyx.merge` and to `Onyx.update` with the method "MERGE"
295
+ */
296
+ type OnyxMergeInput<TKey extends OnyxKey> = OnyxInput<NullishDeep<KeyValueMapping[TKey]>>;
297
+ /**
298
+ * This represents the value that can be passed to `Onyx.merge` and to `Onyx.update` with the method "MERGE"
299
+ */
300
+ type OnyxMergeCollectionInput<TKey extends OnyxKey, TMap = object> = Collection<TKey, NullishDeep<KeyValueMapping[TKey]>, TMap>;
279
301
  /**
280
302
  * Represents different kinds of updates that can be passed to `Onyx.update()` method. It is a discriminated union of
281
303
  * different update methods (`SET`, `MERGE`, `MERGE_COLLECTION`), each with their own key and value structure.
@@ -284,15 +306,15 @@ type OnyxUpdate = {
284
306
  [TKey in OnyxKey]: {
285
307
  onyxMethod: typeof OnyxUtils.METHOD.SET;
286
308
  key: TKey;
287
- value: NonUndefined<OnyxEntry<KeyValueMapping[TKey]>>;
309
+ value: OnyxSetInput<TKey>;
288
310
  } | {
289
- onyxMethod: typeof OnyxUtils.METHOD.MERGE;
311
+ onyxMethod: typeof OnyxUtils.METHOD.MULTI_SET;
290
312
  key: TKey;
291
- value: NonUndefined<OnyxEntry<NullishDeep<KeyValueMapping[TKey]>>>;
313
+ value: OnyxMultiSetInput;
292
314
  } | {
293
- onyxMethod: typeof OnyxUtils.METHOD.MULTI_SET;
315
+ onyxMethod: typeof OnyxUtils.METHOD.MERGE;
294
316
  key: TKey;
295
- value: Partial<NullableKeyValueMapping>;
317
+ value: OnyxMergeInput<TKey>;
296
318
  } | {
297
319
  onyxMethod: typeof OnyxUtils.METHOD.CLEAR;
298
320
  key: TKey;
@@ -302,7 +324,7 @@ type OnyxUpdate = {
302
324
  [TKey in CollectionKeyBase]: {
303
325
  onyxMethod: typeof OnyxUtils.METHOD.MERGE_COLLECTION;
304
326
  key: TKey;
305
- value: Record<`${TKey}${string}`, NullishDeep<KeyValueMapping[TKey]>>;
327
+ value: OnyxMergeCollectionInput<TKey>;
306
328
  };
307
329
  }[CollectionKeyBase];
308
330
  /**
@@ -333,4 +355,4 @@ type InitOptions = {
333
355
  debugSetState?: boolean;
334
356
  };
335
357
  type GenericFunction = (...args: any[]) => any;
336
- export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionConnectOptions, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, DefaultConnectOptions, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, Mapping, NonNull, NonUndefined, NullableKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxUpdate, OnyxValue, Selector, WithOnyxConnectOptions, };
358
+ export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionConnectOptions, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, DefaultConnectOptions, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, Mapping, NonNull, NonUndefined, NullableKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector, WithOnyxConnectOptions, };
@@ -1,6 +1,6 @@
1
1
  import type { ForwardedRef } from 'react';
2
2
  import type { IsEqual } from 'type-fest';
3
- import type { CollectionKeyBase, ExtractOnyxCollectionValue, KeyValueMapping, NullableKeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, Selector } from '../types';
3
+ import type { CollectionKeyBase, ExtractOnyxCollectionValue, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, OnyxValue, Selector } from '../types';
4
4
  /**
5
5
  * Represents the base mapping options between an Onyx key and the component's prop.
6
6
  */
@@ -134,7 +134,7 @@ type WithOnyxState<TOnyxProps> = TOnyxProps & {
134
134
  /**
135
135
  * Represents the `withOnyx` internal component instance.
136
136
  */
137
- type WithOnyxInstance = React.Component<unknown, WithOnyxState<NullableKeyValueMapping>> & {
137
+ type WithOnyxInstance = React.Component<unknown, WithOnyxState<KeyValueMapping>> & {
138
138
  setStateProxy: (modifier: Record<string, OnyxCollection<KeyValueMapping[OnyxKey]>> | ((state: Record<string, OnyxCollection<KeyValueMapping[OnyxKey]>>) => OnyxValue<OnyxKey>)) => void;
139
139
  setWithOnyxState: (statePropertyName: OnyxKey, value: OnyxValue<OnyxKey>) => void;
140
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.43",
3
+ "version": "2.0.45",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",