diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index 73f16215..78fb050e 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -59,6 +59,10 @@ type UseOnyxResult = [CachedValue, R type UseOnyxSelector = (data?: OnyxValue) => SelectorValue; +/** + * Gets the cached value from the Onyx cache. If the key is a collection key, it will return all the values in the collection. + * It is a fork of `tryGetCachedValue` from `OnyxUtils` caused by different selector logic in `useOnyx`. It should be unified in the future, when `withOnyx` is removed. + */ function getCachedValue(key: TKey): OnyxValue | undefined { if (!OnyxUtils.isCollectionKey(key)) { return OnyxCache.get(key) as OnyxValue | undefined; @@ -84,6 +88,9 @@ function getCachedValue(key: TKey): OnyxValue | unde return values as OnyxValue; } +/** + * Gets the value from cache and maps it with selector. + */ function getSelectedValue | undefined>(key: TKey, selector?: UseOnyxSelector) { const value = getCachedValue(key);