Skip to content

Commit dbeec9e

Browse files
committed
Rename noopCheck to identityFunctionCheck
1 parent 643297b commit dbeec9e

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

docs/api/hooks.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type CheckFrequency = 'never' | 'once' | 'always'
5353
interface UseSelectorOptions {
5454
equalityFn?: EqualityFn
5555
stabilityCheck?: CheckFrequency
56-
noopCheck?: CheckFrequency
56+
identityFunctionCheck?: CheckFrequency
5757
}
5858

5959
const result: Selected = useSelector(
@@ -303,7 +303,7 @@ function Component() {
303303
}
304304
```
305305

306-
#### No-op selector check
306+
#### `identityFunctionCheck`
307307

308308
In development, a check is conducted on the result returned by the selector. It warns in the console if the result is the same as the parameter passed in, i.e. the root state.
309309

@@ -321,16 +321,16 @@ const user = useSelector((state) => state.auth.currentUser)
321321
By default, this will only happen when the selector is first called. You can configure the check in the Provider or at each `useSelector` call.
322322

323323
```tsx title="Global setting via context"
324-
<Provider store={store} noopCheck="always">
324+
<Provider store={store} identityFunctionCheck="always">
325325
{children}
326326
</Provider>
327327
```
328328

329329
```tsx title="Individual hook setting"
330330
function Component() {
331-
const count = useSelector(selectCount, { noopCheck: 'never' })
331+
const count = useSelector(selectCount, { identityFunctionCheck: 'never' })
332332
// run once (default)
333-
const user = useSelector(selectUser, { noopCheck: 'once' })
333+
const user = useSelector(selectUser, { identityFunctionCheck: 'once' })
334334
// ...
335335
}
336336
```

src/components/Context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from 'react'
21
import type { Context } from 'react'
2+
import * as React from 'react'
33
import type { Action, Store, UnknownAction } from 'redux'
4-
import type { Subscription } from '../utils/Subscription'
54
import type { CheckFrequency } from '../hooks/useSelector'
5+
import type { Subscription } from '../utils/Subscription'
66

77
export interface ReactReduxContextValue<
88
SS = any,
@@ -12,7 +12,7 @@ export interface ReactReduxContextValue<
1212
subscription: Subscription
1313
getServerState?: () => SS
1414
stabilityCheck: CheckFrequency
15-
noopCheck: CheckFrequency
15+
identityFunctionCheck: CheckFrequency
1616
}
1717

1818
const ContextKey = Symbol.for(`react-redux-context`)

src/components/Provider.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export interface ProviderProps<
3232
/** Global configuration for the `useSelector` stability check */
3333
stabilityCheck?: CheckFrequency
3434

35-
/** Global configuration for the `useSelector` no-op check */
36-
noopCheck?: CheckFrequency
35+
/** Global configuration for the `useSelector` identity function check */
36+
identityFunctionCheck?: CheckFrequency
3737

3838
children: ReactNode
3939
}
@@ -44,7 +44,7 @@ function Provider<A extends Action<string> = UnknownAction, S = unknown>({
4444
children,
4545
serverState,
4646
stabilityCheck = 'once',
47-
noopCheck = 'once',
47+
identityFunctionCheck = 'once',
4848
}: ProviderProps<A, S>) {
4949
const contextValue = React.useMemo(() => {
5050
const subscription = createSubscription(store)
@@ -53,9 +53,9 @@ function Provider<A extends Action<string> = UnknownAction, S = unknown>({
5353
subscription,
5454
getServerState: serverState ? () => serverState : undefined,
5555
stabilityCheck,
56-
noopCheck,
56+
identityFunctionCheck,
5757
}
58-
}, [store, serverState, stabilityCheck, noopCheck])
58+
}, [store, serverState, stabilityCheck, identityFunctionCheck])
5959

6060
const previousState = React.useMemo(() => store.getState(), [store])
6161

src/hooks/useSelector.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import * as React from 'react'
22

3-
import {
4-
createReduxContextHook,
5-
useReduxContext as useDefaultReduxContext,
6-
} from './useReduxContext'
73
import type { ReactReduxContextValue } from '../components/Context'
84
import { ReactReduxContext } from '../components/Context'
95
import type { EqualityFn, NoInfer } from '../types'
106
import type { uSESWS } from '../utils/useSyncExternalStore'
117
import { notInitialized } from '../utils/useSyncExternalStore'
8+
import {
9+
createReduxContextHook,
10+
useReduxContext as useDefaultReduxContext,
11+
} from './useReduxContext'
1212

1313
export type CheckFrequency = 'never' | 'once' | 'always'
1414

1515
export interface UseSelectorOptions<Selected = unknown> {
1616
equalityFn?: EqualityFn<Selected>
1717
stabilityCheck?: CheckFrequency
18-
noopCheck?: CheckFrequency
18+
identityFunctionCheck?: CheckFrequency
1919
}
2020

2121
export interface UseSelector {
@@ -62,7 +62,7 @@ export function createSelectorHook(
6262
const {
6363
equalityFn = refEquality,
6464
stabilityCheck = undefined,
65-
noopCheck = undefined,
65+
identityFunctionCheck = undefined,
6666
} = typeof equalityFnOrOptions === 'function'
6767
? { equalityFn: equalityFnOrOptions }
6868
: equalityFnOrOptions
@@ -85,7 +85,7 @@ export function createSelectorHook(
8585
subscription,
8686
getServerState,
8787
stabilityCheck: globalStabilityCheck,
88-
noopCheck: globalNoopCheck,
88+
identityFunctionCheck: globalIdentityFunctionCheck,
8989
} = useReduxContext()
9090

9191
const firstRun = React.useRef(true)
@@ -125,11 +125,11 @@ export function createSelectorHook(
125125
)
126126
}
127127
}
128-
const finalNoopCheck =
129-
typeof noopCheck === 'undefined' ? globalNoopCheck : noopCheck
128+
const finalIdentityFunctionCheck =
129+
typeof identityFunctionCheck === 'undefined' ? globalIdentityFunctionCheck : identityFunctionCheck
130130
if (
131-
finalNoopCheck === 'always' ||
132-
(finalNoopCheck === 'once' && firstRun.current)
131+
finalIdentityFunctionCheck === 'always' ||
132+
(finalIdentityFunctionCheck === 'once' && firstRun.current)
133133
) {
134134
// @ts-ignore
135135
if (selected === state) {

test/hooks/useSelector.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import type { UseSelectorOptions } from '../../src/hooks/useSelector'
3333
// disable checks by default
3434
function ProviderMock<A extends Action<any> = AnyAction, S = unknown>({
3535
stabilityCheck = 'never',
36-
noopCheck = 'never',
36+
identityFunctionCheck = 'never',
3737
...props
3838
}: ProviderProps<A, S>) {
3939
return (
4040
<Provider
4141
{...props}
4242
stabilityCheck={stabilityCheck}
43-
noopCheck={noopCheck}
43+
identityFunctionCheck={identityFunctionCheck}
4444
/>
4545
)
4646
}
@@ -1028,10 +1028,10 @@ describe('React', () => {
10281028
expect(selector).toHaveBeenCalledTimes(4)
10291029
})
10301030
})
1031-
describe('no-op selector check', () => {
1031+
describe('identity function check', () => {
10321032
it('warns for selectors that return the entire root state', () => {
10331033
rtl.render(
1034-
<ProviderMock noopCheck="once" store={normalStore}>
1034+
<ProviderMock identityFunctionCheck="once" store={normalStore}>
10351035
<RenderSelector selector={(state) => state.count} />
10361036
</ProviderMock>
10371037
)
@@ -1041,7 +1041,7 @@ describe('React', () => {
10411041
rtl.cleanup()
10421042

10431043
rtl.render(
1044-
<ProviderMock noopCheck="once" store={normalStore}>
1044+
<ProviderMock identityFunctionCheck="once" store={normalStore}>
10451045
<RenderSelector selector={(state) => state} />
10461046
</ProviderMock>
10471047
)

0 commit comments

Comments
 (0)