Skip to content

Commit c536318

Browse files
committed
Remove "Top-Level Selectors" since createSlice handles this in RTK 2.0
1 parent 47fd0b5 commit c536318

File tree

1 file changed

+0
-41
lines changed

1 file changed

+0
-41
lines changed

README.md

-41
Original file line numberDiff line numberDiff line change
@@ -1324,47 +1324,6 @@ const selectorBad = createSelector(
13241324

13251325
---
13261326

1327-
## Additional Tips & Tricks
1328-
1329-
<details><summary><b>Top Level Selectors Pattern</b></summary>
1330-
1331-
This pattern simplifies the creation of selectors in your application. Start by defining a generic type for your top-level selectors:
1332-
1333-
```ts
1334-
import type { Selector } from 'reselect'
1335-
1336-
export type TopLevelSelectors<State> = {
1337-
[K in keyof State as K extends string
1338-
? `select${Capitalize<K>}`
1339-
: never]: Selector<State, State[K], never>
1340-
}
1341-
```
1342-
1343-
With this setup, you can easily create top-level selectors for your application's state:
1344-
1345-
```ts
1346-
const topLevelSelectors: TopLevelSelectors<RootState> = {
1347-
selectAlerts: state => state.alerts,
1348-
selectTodos: state => state.todos,
1349-
selectUsers: state => state.users
1350-
}
1351-
```
1352-
1353-
This approach allows for more streamlined and readable selector creation. For example:
1354-
1355-
```ts
1356-
const selectCompletedTodos = createSelector(
1357-
[topLevelSelectors.selectTodos],
1358-
todos => todos.filter(todo => todo.completed === true)
1359-
)
1360-
```
1361-
1362-
</details>
1363-
1364-
<div align="right">[ <a href="#table-of-contents">↑ Back to top ↑</a> ]</div>
1365-
1366-
---
1367-
13681327
## FAQ
13691328

13701329
### Why isn’t my selector recomputing when the input state changes?

0 commit comments

Comments
 (0)