Skip to content

Commit

Permalink
Add reuseConnection support to useOnyx() for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioh8010 committed Oct 8, 2024
1 parent d8fc63f commit ceef41f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/useOnyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type BaseUseOnyxOptions = {
* If set to `true`, data will be retrieved from cache during the first render even if there is a pending merge for the key.
*/
allowStaleData?: boolean;

/**
* If set to `false`, the connection won't be reused between other subscribers that are listening to the same Onyx key
* with the same connect configurations.
*/
reuseConnection?: boolean;
};

type UseOnyxInitialValueOption<TInitialValue> = {
Expand Down Expand Up @@ -261,6 +267,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey
},
initWithStoredValues: options?.initWithStoredValues,
waitForCollectionCallback: OnyxUtils.isCollectionKey(key) as true,
reuseConnection: options?.reuseConnection,
});

checkEvictableKey();
Expand All @@ -274,7 +281,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey
isFirstConnectionRef.current = false;
};
},
[key, options?.initWithStoredValues, checkEvictableKey],
[key, options?.initWithStoredValues, options?.reuseConnection, checkEvictableKey],
);

useEffect(() => {
Expand Down

0 comments on commit ceef41f

Please sign in to comment.