Skip to content

Commit 084b87c

Browse files
EskiMojo14msutkowski
authored andcommitted
Apply suggestions from code review
Co-authored-by: Matt Sutkowski <msutkowski@gmail.com>
1 parent da91d73 commit 084b87c

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

docs/api/hooks.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,20 @@ There are some differences between the selectors passed to `useSelector()` and a
313313

314314
#### No-op selector check
315315

316-
In development, a check is conducted on the result returned by the selector. It warns in console if the result is the same as the parameter passed in, i.e. the root state.
316+
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.
317317

318-
A `useSelector` call returning the entire root state is almost always a mistake, as it means the component will rerender whenever _anything_ in state changes. Selectors should select as specifically as possible.
318+
A `useSelector` call returning the entire root state is almost always a mistake, as it means the component will rerender whenever _anything_ in state changes. Selectors should be as granular as possible.
319319

320320
```ts no-transpile
321-
// this selector returns the entire state, meaning that the component will rerender unnecessarily
321+
// BAD: this selector returns the entire state, meaning that the component will rerender unnecessarily
322322
const { count, user } = useSelector((state) => state)
323323

324-
// instead, select only the state you need, calling useSelector as many times as needed
324+
// GOOD: instead, select only the state you need, calling useSelector as many times as needed
325325
const count = useSelector((state) => state.count)
326326
const user = useSelector((state) => state.user)
327327
```
328328

329-
By default, this will only happen when the selector is first called. You can configure the check via context, or per `useSelector` call - either to run the check always, or never.
329+
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.
330330

331331
```tsx title="Global setting via context"
332332
<Provider store={store} noopCheck="always">

src/components/Context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createContext } from 'react'
22
import type { Action, AnyAction, Store } from 'redux'
33
import type { Subscription } from '../utils/Subscription'
4-
import { CheckFrequency } from '../hooks/useSelector'
4+
import type { CheckFrequency } from '../hooks/useSelector'
55

66
export interface ReactReduxContextValue<
77
SS = any,

src/components/Provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ReactReduxContext, ReactReduxContextValue } from './Context'
33
import { createSubscription } from '../utils/Subscription'
44
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
55
import { Action, AnyAction, Store } from 'redux'
6-
import { CheckFrequency } from '../hooks/useSelector'
6+
import type { CheckFrequency } from '../hooks/useSelector'
77

88
export interface ProviderProps<A extends Action = AnyAction, S = unknown> {
99
/**

test/hooks/useSelector.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type {
2626
} from '../../src/index'
2727
import type { FunctionComponent, DispatchWithoutAction, ReactNode } from 'react'
2828
import type { Store, AnyAction } from 'redux'
29-
import { UseSelectorOptions } from '../../src/hooks/useSelector'
29+
import type { UseSelectorOptions } from '../../src/hooks/useSelector'
3030

3131
// disable checks by default
3232
function ProviderMock<A extends Action<any> = AnyAction, S = unknown>({

0 commit comments

Comments
 (0)