Skip to content

Commit

Permalink
fix copy&paste accidents
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-mikolajczak committed Oct 2, 2024
1 parent 4629b78 commit 81127bf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/useOnyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey

// Stores the previously result returned by the hook, containing the data from cache and the fetch status.
// We initialize it to `undefined` and `loading` fetch status to simulate the initial result when the hook is loading from the cache.
// However, if `initWithStoredValues` is `true` we set the fetch status to `loaded` since we want to signal that data is ready.
// However, if `initWithStoredValues` is `false` we set the fetch status to `loaded` since we want to signal that data is ready.
const resultRef = useRef<UseOnyxResult<TReturnValue>>([
undefined,
{
Expand Down Expand Up @@ -180,6 +180,11 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey
}, [key, options?.canEvict]);

const getSnapshot = useCallback(() => {
// We return the initial result right away during the first connection if `initWithStoredValues` is set to `false`.
if (isFirstConnectionRef.current && options?.initWithStoredValues === false) {
return resultRef.current;
}

// We get the value from cache while the first connection to Onyx is being made,
// so we can return any cached value right away. After the connection is made, we only
// update `newValueRef` when `Onyx.connect()` callback is fired.
Expand Down Expand Up @@ -237,7 +242,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey
}

return resultRef.current;
}, [key, selectorRef, options?.allowStaleData, options?.initialValue]);
}, [options?.initWithStoredValues, options?.allowStaleData, options?.initialValue, key, selectorRef]);

const subscribe = useCallback(
(onStoreChange: () => void) => {
Expand Down

0 comments on commit 81127bf

Please sign in to comment.