You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Use a custom equality function as the `equalityFn` argument to `useSelector()`, like:
@@ -240,6 +245,46 @@ export const App = () => {
240
245
}
241
246
```
242
247
248
+
### Development mode checks
249
+
250
+
#### Selector result stability
251
+
252
+
In development, an extra check is conducted on the passed selector. It runs the selector an extra time with the same parameter, and warns in console if it returns a different result (based on the `equalityFn` provided).
253
+
254
+
This is important, as a selector returning a materially different result with the same parameter will cause unnecessary rerenders.
255
+
256
+
```ts
257
+
// this selector will return a new object reference whenever called
258
+
// meaning the component will rerender whenever *any* action is dispatched
259
+
const { count, user } =useSelector((state) => ({
260
+
count: state.count,
261
+
user: state.user,
262
+
}))
263
+
```
264
+
265
+
If a selector result is suitably stable, or memoised, it will not return a different result and thus not cause a warning to be logged.
266
+
267
+
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.
0 commit comments