Add selector composition example for playground usage#305
Add selector composition example for playground usage#305narutamaaurum wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the documentation and a playground component to adopt feature-specific selectors, replacing direct state access with countersSelectors.getReduxCounter. It introduces an adapter pattern at the composition layer to map root state to feature state, enhancing reusability. The review feedback correctly identifies that the documentation examples are missing the RootState type import and should clarify that useSelector must be called within a React component context for technical accuracy.
| import { countersSelectors } from '../features/counters'; | ||
| import { useSelector } from '../store/hooks'; | ||
|
|
||
| const selectReduxCounter = (state: RootState) => | ||
| countersSelectors.getReduxCounter(state.counters); | ||
|
|
||
| const counter = useSelector(selectReduxCounter); |
There was a problem hiding this comment.
The code snippet uses RootState as a type annotation but does not include its import. To make the example complete and copy-pasteable, please add the import from MyTypes. Additionally, useSelector should be called within a React component context to be technically accurate.
| import { countersSelectors } from '../features/counters'; | |
| import { useSelector } from '../store/hooks'; | |
| const selectReduxCounter = (state: RootState) => | |
| countersSelectors.getReduxCounter(state.counters); | |
| const counter = useSelector(selectReduxCounter); | |
| import { RootState } from 'MyTypes'; | |
| import { countersSelectors } from '../features/counters'; | |
| import { useSelector } from '../store/hooks'; | |
| const selectReduxCounter = (state: RootState) => | |
| countersSelectors.getReduxCounter(state.counters); | |
| // inside a component | |
| const counter = useSelector(selectReduxCounter); |
| import { countersSelectors } from '../features/counters'; | ||
| import { useSelector } from '../store/hooks'; | ||
|
|
||
| const selectReduxCounter = (state: RootState) => | ||
| countersSelectors.getReduxCounter(state.counters); | ||
|
|
||
| const counter = useSelector(selectReduxCounter); |
There was a problem hiding this comment.
The code snippet uses RootState as a type annotation but does not include its import. To make the example complete and copy-pasteable, please add the import from MyTypes. Additionally, useSelector should be called within a React component context to be technically accurate.
| import { countersSelectors } from '../features/counters'; | |
| import { useSelector } from '../store/hooks'; | |
| const selectReduxCounter = (state: RootState) => | |
| countersSelectors.getReduxCounter(state.counters); | |
| const counter = useSelector(selectReduxCounter); | |
| import { RootState } from 'MyTypes'; | |
| import { countersSelectors } from '../features/counters'; | |
| import { useSelector } from '../store/hooks'; | |
| const selectReduxCounter = (state: RootState) => | |
| countersSelectors.getReduxCounter(state.counters); | |
| // inside a component | |
| const counter = useSelector(selectReduxCounter); |
|
Addressed the review note in this branch update. The selector-composition snippet now imports the root-state type explicitly and wraps the |
Closes #109
Summary
RootStateto feature state when reusing feature selectorscountersSelectors.getReduxCounterValidation
npm run ci-checkcd playground && npm run tsc