1
1
//import * as React from 'react'
2
2
import { React } from '../utils/react'
3
-
3
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js'
4
4
import type { ReactReduxContextValue } from '../components/Context'
5
5
import { ReactReduxContext } from '../components/Context'
6
6
import type { EqualityFn , NoInfer } from '../types'
7
- import type { uSESWS } from '../utils/useSyncExternalStore'
8
- import { notInitialized } from '../utils/useSyncExternalStore'
9
7
import {
10
8
createReduxContextHook ,
11
9
useReduxContext as useDefaultReduxContext ,
@@ -118,11 +116,6 @@ export interface UseSelector<StateType = unknown> {
118
116
> ( ) => UseSelector < OverrideStateType >
119
117
}
120
118
121
- let useSyncExternalStoreWithSelector = notInitialized as uSESWS
122
- export const initializeUseSelector = ( fn : uSESWS ) => {
123
- useSyncExternalStoreWithSelector = fn
124
- }
125
-
126
119
const refEquality : EqualityFn < any > = ( a , b ) => a === b
127
120
128
121
/**
@@ -148,7 +141,7 @@ export function createSelectorHook(
148
141
| EqualityFn < NoInfer < Selected > >
149
142
| UseSelectorOptions < NoInfer < Selected > > = { } ,
150
143
) : Selected => {
151
- const { equalityFn = refEquality , devModeChecks = { } } =
144
+ const { equalityFn = refEquality } =
152
145
typeof equalityFnOrOptions === 'function'
153
146
? { equalityFn : equalityFnOrOptions }
154
147
: equalityFnOrOptions
@@ -166,13 +159,9 @@ export function createSelectorHook(
166
159
}
167
160
}
168
161
169
- const {
170
- store,
171
- subscription,
172
- getServerState,
173
- stabilityCheck,
174
- identityFunctionCheck,
175
- } = useReduxContext ( )
162
+ const reduxContext = useReduxContext ( )
163
+
164
+ const { store, subscription, getServerState } = reduxContext
176
165
177
166
const firstRun = React . useRef ( true )
178
167
@@ -181,6 +170,11 @@ export function createSelectorHook(
181
170
[ selector . name ] ( state : TState ) {
182
171
const selected = selector ( state )
183
172
if ( process . env . NODE_ENV !== 'production' ) {
173
+ const { devModeChecks = { } } =
174
+ typeof equalityFnOrOptions === 'function'
175
+ ? { }
176
+ : equalityFnOrOptions
177
+ const { identityFunctionCheck, stabilityCheck } = reduxContext
184
178
const {
185
179
identityFunctionCheck : finalIdentityFunctionCheck ,
186
180
stabilityCheck : finalStabilityCheck ,
@@ -243,7 +237,7 @@ export function createSelectorHook(
243
237
return selected
244
238
} ,
245
239
} [ selector . name ] ,
246
- [ selector , stabilityCheck , devModeChecks . stabilityCheck ] ,
240
+ [ selector ] ,
247
241
)
248
242
249
243
const selectedState = useSyncExternalStoreWithSelector (
0 commit comments