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