Download reselect/docs/examples/weakMapMemoize/usingWithCreateSelector.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 907 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/weakMapMemoize/usingWithCreateSelector.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/weakMapMemoize/usingWithCreateSelector.ts
-
curl -L -o usingWithCreateSelector.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/reselect/docs/examples/weakMapMemoize/usingWithCreateSelector.ts
907 Bytes
| import { createSelector, weakMapMemoize } from 'reselect' | |
| import type { RootState } from './cacheSizeProblem' | |
| const state: RootState = { | |
| items: [ | |
| { id: 1, category: 'Electronics', name: 'Wireless Headphones' }, | |
| { id: 2, category: 'Books', name: 'The Great Gatsby' }, | |
| { id: 3, category: 'Home Appliances', name: 'Blender' }, | |
| { id: 4, category: 'Stationery', name: 'Sticky Notes' } | |
| ] | |
| } | |
| const selectItemsByCategory = createSelector( | |
| [ | |
| (state: RootState) => state.items, | |
| (state: RootState, category: string) => category | |
| ], | |
| (items, category) => items.filter(item => item.category === category), | |
| { | |
| memoize: weakMapMemoize, | |
| argsMemoize: weakMapMemoize | |
| } | |
| ) | |
| selectItemsByCategory(state, 'Electronics') // Selector runs | |
| selectItemsByCategory(state, 'Electronics') | |
| selectItemsByCategory(state, 'Stationery') // Selector runs | |
| selectItemsByCategory(state, 'Electronics') | |