Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ _Found it useful? Want more updates?_
Check out our Playground Project located in the `/playground` folder. It contains all source files of the code examples found in the guide. They are all tested with the most recent version of TypeScript and 3rd party type-definitions (like `@types/react` or `@types/react-redux`) to ensure the examples are up-to-date and not broken with updated definitions (It's based on `create-react-app --typescript`).
> Playground project was created so that you can simply clone the repository locally and immediately play around with all the component patterns found in the guide. It will help you to learn all the examples from this guide in a real project environment without the need to create complicated environment setup by yourself.

### Selectors in Playground

Selectors are defined in each feature module and consumed from connected components and hooks.
Because feature selectors accept feature state, adapt from `RootState` in one place:

```ts
const mapStateToProps = (state: Types.RootState) => ({
count: countersSelectors.getReduxCounter(state.counters),
});
```

Example files in playground:

- `src/connected/fc-counter-connected.tsx`
- `src/connected/fc-counter-connected-own-props.tsx`
- `src/hooks/react-redux-hooks.tsx`

## Contributing Guide

You can help make this project better by contributing. If you're planning to contribute please make sure to check our contributing guide: [CONTRIBUTING.md](/CONTRIBUTING.md)
Expand Down Expand Up @@ -1068,11 +1085,12 @@ export default () => (
```tsx
import * as React from 'react';
import { FCCounter } from '../components';
import { countersSelectors } from '../features/counters';
import { increment } from '../features/counters/actions';
import { useSelector, useDispatch } from '../store/hooks';

const FCCounterConnectedHooksUsage: React.FC = () => {
const counter = useSelector(state => state.counters.reduxCounter);
const counter = useSelector(state => countersSelectors.getReduxCounter(state.counters));
const dispatch = useDispatch();
return <FCCounter label="Use selector" count={counter} onIncrement={() => dispatch(increment())}/>;
};
Expand Down
17 changes: 17 additions & 0 deletions README_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ _Found it useful? Want more updates?_
Check out our Playground Project located in the `/playground` folder. It contains all source files of the code examples found in the guide. They are all tested with the most recent version of TypeScript and 3rd party type-definitions (like `@types/react` or `@types/react-redux`) to ensure the examples are up-to-date and not broken with updated definitions (It's based on `create-react-app --typescript`).
> Playground project was created so that you can simply clone the repository locally and immediately play around with all the component patterns found in the guide. It will help you to learn all the examples from this guide in a real project environment without the need to create complicated environment setup by yourself.

### Selectors in Playground

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

It appears that the updates made to the hooks example in README.md (around line 1085) were not applied to this file. Since README.md is typically generated from README_SOURCE.md, these changes might be lost in future updates. Please ensure both files are kept in sync.


Selectors are defined in each feature module and consumed from connected components and hooks.
Because feature selectors accept feature state, adapt from `RootState` in one place:

```ts
const mapStateToProps = (state: Types.RootState) => ({
count: countersSelectors.getReduxCounter(state.counters),
});
```

Example files in playground:

- `src/connected/fc-counter-connected.tsx`
- `src/connected/fc-counter-connected-own-props.tsx`
- `src/hooks/react-redux-hooks.tsx`

## Contributing Guide

You can help make this project better by contributing. If you're planning to contribute please make sure to check our contributing guide: [CONTRIBUTING.md](/CONTRIBUTING.md)
Expand Down
3 changes: 2 additions & 1 deletion playground/src/hooks/react-redux-hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { FCCounter } from '../components';
import { countersSelectors } from '../features/counters';
import { increment } from '../features/counters/actions';
import { useSelector, useDispatch } from '../store/hooks';

const FCCounterConnectedHooksUsage: React.FC = () => {
const counter = useSelector(state => state.counters.reduxCounter);
const counter = useSelector(state => countersSelectors.getReduxCounter(state.counters));
const dispatch = useDispatch();
return <FCCounter label="Use selector" count={counter} onIncrement={() => dispatch(increment())}/>;
};
Expand Down