@@ -78,13 +78,11 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
7878 const previousKey = usePrevious ( key ) ;
7979
8080 const currentDependenciesRef = useLiveRef ( dependencies ) ;
81- const selector = options ?. selector ;
81+ const currentSelectorRef = useLiveRef ( options ?. selector ) ;
8282
8383 // Create memoized version of selector for performance
8484 const memoizedSelector = useMemo ( ( ) => {
85- if ( ! selector ) {
86- return null ;
87- }
85+ if ( ! options ?. selector ) return null ;
8886
8987 let lastInput : OnyxValue < TKey > | undefined ;
9088 let lastOutput : TReturnValue ;
@@ -93,13 +91,14 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
9391
9492 return ( input : OnyxValue < TKey > | undefined ) : TReturnValue => {
9593 const currentDependencies = currentDependenciesRef . current ;
94+ const currentSelector = currentSelectorRef . current ;
9695
9796 // Recompute if input changed, dependencies changed, or first time
9897 const dependenciesChanged = ! shallowEqual ( lastDependencies , currentDependencies ) ;
9998 if ( ! hasComputed || lastInput !== input || dependenciesChanged ) {
10099 // Only proceed if we have a valid selector
101- if ( selector ) {
102- const newOutput = selector ( input ) ;
100+ if ( currentSelector ) {
101+ const newOutput = currentSelector ( input ) ;
103102
104103 // Deep equality mode: only update if output actually changed
105104 if ( ! hasComputed || ! deepEqual ( lastOutput , newOutput ) || dependenciesChanged ) {
@@ -113,7 +112,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
113112
114113 return lastOutput ;
115114 } ;
116- } , [ currentDependenciesRef , selector ] ) ;
115+ } , [ currentDependenciesRef , currentSelectorRef , options ?. selector ] ) ;
117116
118117 // Stores the previous cached value as it's necessary to compare with the new value in `getSnapshot()`.
119118 // We initialize it to `null` to simulate that we don't have any value from cache yet.
0 commit comments