react-code-dataset / reselect /docs /examples /handling-empty-array-results /fallbackToEmptyArray.ts
Download reselect/docs/examples/handling-empty-array-results/fallbackToEmptyArray.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 411 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/handling-empty-array-results/fallbackToEmptyArray.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/handling-empty-array-results/fallbackToEmptyArray.ts
-
curl -L -o fallbackToEmptyArray.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/handling-empty-array-results/fallbackToEmptyArray.ts
411 Bytes
| import { createSelector } from 'reselect' | |
| import type { RootState } from './firstPattern' | |
| const EMPTY_ARRAY: [] = [] | |
| export const fallbackToEmptyArray = <T>(array: T[]) => { | |
| return array.length === 0 ? EMPTY_ARRAY : array | |
| } | |
| const selectCompletedTodos = createSelector( | |
| [(state: RootState) => state.todos], | |
| todos => { | |
| return fallbackToEmptyArray(todos.filter(todo => todo.completed === true)) | |
| } | |
| ) | |