react-code-dataset / reselect /docs /examples /development-only-stability-checks /inputStabilityCheck.ts
Download reselect/docs/examples/development-only-stability-checks/inputStabilityCheck.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 665 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/development-only-stability-checks/inputStabilityCheck.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/development-only-stability-checks/inputStabilityCheck.ts
-
curl -L -o inputStabilityCheck.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/development-only-stability-checks/inputStabilityCheck.ts
665 Bytes
| import { createSelector } from 'reselect' | |
| interface RootState { | |
| todos: { id: number; completed: boolean }[] | |
| alerts: { id: number; read: boolean }[] | |
| } | |
| // Create a selector that double-checks the results of input selectors every time it runs. | |
| const selectCompletedTodosLength = createSelector( | |
| [ | |
| // ❌ Incorrect Use Case: This input selector will not be | |
| // memoized properly since it always returns a new reference. | |
| (state: RootState) => | |
| state.todos.filter(({ completed }) => completed === true) | |
| ], | |
| completedTodos => completedTodos.length, | |
| // Will override the global setting. | |
| { devModeChecks: { inputStabilityCheck: 'always' } } | |
| ) | |