Skip to content

Add selector composition example for playground usage#305

Open
narutamaaurum wants to merge 2 commits into
piotrwitek:masterfrom
narutamaaurum:fix-109-selectors-playground
Open

Add selector composition example for playground usage#305
narutamaaurum wants to merge 2 commits into
piotrwitek:masterfrom
narutamaaurum:fix-109-selectors-playground

Conversation

@narutamaaurum

Copy link
Copy Markdown

Closes #109

Summary

  • show how to adapt RootState to feature state when reusing feature selectors
  • update the hooks playground example to use countersSelectors.getReduxCounter
  • document the selector composition pattern in the README

Validation

  • npm run ci-check
  • cd playground && npm run tsc

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md Outdated
Comment on lines +1769 to +1775
import { countersSelectors } from '../features/counters';
import { useSelector } from '../store/hooks';

const selectReduxCounter = (state: RootState) =>
countersSelectors.getReduxCounter(state.counters);

const counter = useSelector(selectReduxCounter);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);

Comment thread README_SOURCE.md Outdated
Comment on lines +660 to +666
import { countersSelectors } from '../features/counters';
import { useSelector } from '../store/hooks';

const selectReduxCounter = (state: RootState) =>
countersSelectors.getReduxCounter(state.counters);

const counter = useSelector(selectReduxCounter);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);

@narutamaaurum

Copy link
Copy Markdown
Author

Addressed the review note in this branch update. The selector-composition snippet now imports the root-state type explicitly and wraps the useSelector call in a small React component so the example is copy-pasteable and technically accurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selectors in the playground?

1 participant