@@ -78,11 +78,13 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
7878 const previousKey = usePrevious ( key ) ;
7979
8080 const currentDependenciesRef = useLiveRef ( dependencies ) ;
81- const currentSelectorRef = useLiveRef ( options ?. selector ) ;
81+ const selector = options ?. selector ;
8282
8383 // Create memoized version of selector for performance
8484 const memoizedSelector = useMemo ( ( ) => {
85- if ( ! options ?. selector ) return null ;
85+ if ( ! selector ) {
86+ return null ;
87+ }
8688
8789 let lastInput : OnyxValue < TKey > | undefined ;
8890 let lastOutput : TReturnValue ;
@@ -91,14 +93,13 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
9193
9294 return ( input : OnyxValue < TKey > | undefined ) : TReturnValue => {
9395 const currentDependencies = currentDependenciesRef . current ;
94- const currentSelector = currentSelectorRef . current ;
9596
9697 // Recompute if input changed, dependencies changed, or first time
9798 const dependenciesChanged = ! shallowEqual ( lastDependencies , currentDependencies ) ;
9899 if ( ! hasComputed || lastInput !== input || dependenciesChanged ) {
99100 // Only proceed if we have a valid selector
100- if ( currentSelector ) {
101- const newOutput = currentSelector ( input ) ;
101+ if ( selector ) {
102+ const newOutput = selector ( input ) ;
102103
103104 // Deep equality mode: only update if output actually changed
104105 if ( ! hasComputed || ! deepEqual ( lastOutput , newOutput ) || dependenciesChanged ) {
@@ -112,7 +113,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
112113
113114 return lastOutput ;
114115 } ;
115- } , [ currentDependenciesRef , currentSelectorRef , options ?. selector ] ) ;
116+ } , [ currentDependenciesRef , selector ] ) ;
116117
117118 // Stores the previous cached value as it's necessary to compare with the new value in `getSnapshot()`.
118119 // We initialize it to `null` to simulate that we don't have any value from cache yet.
0 commit comments