You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue tracker is meant for bug reports only. This isn't the best place for support or usage questions. Questions here don't have as much visibility as they do elsewhere. Before you ask a question, here are some resources to get help first:
13
+
14
+
- Read the docs: https://react-redux.js.org/
15
+
- Check out the troubleshooting guide: https://react-redux.js.org/troubleshooting
16
+
- Look for/ask questions on Stack Overflow: https://stackoverflow.com/questions/tagged/redux
17
+
- Ask in chat: https://www.reactiflux.com/
18
+
19
+
Think you found a bug?
20
+
======================
21
+
The best bug report is a failing test in the repository as a pull request. Otherwise, please use the template below.
22
+
23
+
-->
24
+
25
+
**What is the current behavior?**
26
+
27
+
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to a CodeSandbox (https://codesandbox.io/s/new) or RN Snack (https://snack.expo.io/) example below:
28
+
29
+
30
+
31
+
**What is the expected behavior?**
32
+
33
+
Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?
Copy file name to clipboardExpand all lines: README.md
+20-2
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,30 @@ Performant and flexible.
11
11
12
12
## Installation
13
13
14
-
React Redux requires **React 16.8.3 or later.**
14
+
### Using Create React App
15
15
16
+
The recommended way to start new apps with React Redux is by using the [official Redux+JS template](https://github.com/reduxjs/cra-template-redux) for [Create React App](https://github.com/facebook/create-react-app), which takes advantage of [Redux Toolkit](https://redux-toolkit.js.org/).
17
+
18
+
```sh
19
+
npx create-react-app my-app --template redux
16
20
```
17
-
npm install --save react-redux
21
+
22
+
### An Existing React App
23
+
24
+
React Redux 7.1 requires **React 16.8.3 or later.**
25
+
26
+
To use React Redux with your React app, install it as a dependency:
27
+
28
+
```bash
29
+
# If you use npm:
30
+
npm install react-redux
31
+
32
+
# Or if you use Yarn:
33
+
yarn add react-redux
18
34
```
19
35
36
+
You'll also need to [install Redux](https://redux.js.org/introduction/installation) and [set up a Redux store](https://redux.js.org/recipes/configuring-your-store/) in your app.
37
+
20
38
This assumes that you’re using [npm](http://npmjs.com/) package manager
21
39
with a module bundler like [Webpack](https://webpack.js.org/) or
22
40
[Browserify](http://browserify.org/) to consume [CommonJS
The number of declared function parameters of `mapDispatchToProps` determines whether they receive ownProps. See notes [here](#the-arity-of-maptoprops-functions).
Allows you to extract data from the Redux store state, using a selector function.
40
40
41
41
> **Note**: The selector function should be [pure](https://en.wikipedia.org/wiki/Pure_function) since it is potentially executed multiple times and at arbitrary points in time.
42
42
43
-
The selector is approximately equivalent to the [`mapStateToProps` argument to `connect`](../using-react-redux/connect-extracting-data-with-mapStateToProps.md) conceptually. The selector will be called with the entire Redux store state as its only argument. The selector will be run whenever the function component renders. `useSelector()` will also subscribe to the Redux store, and run your selector whenever an action is dispatched.
43
+
The selector is approximately equivalent to the [`mapStateToProps` argument to `connect`](../using-react-redux/connect-mapstate) conceptually. The selector will be called with the entire Redux store state as its only argument. The selector will be run whenever the function component renders (unless its reference hasn't changed since a previous render of the component so that a cached result can be returned by the hook without re-running the selector). `useSelector()` will also subscribe to the Redux store, and run your selector whenever an action is dispatched.
44
44
45
45
However, there are some differences between the selectors passed to `useSelector()` and a `mapState` function:
46
46
@@ -57,7 +57,7 @@ You may call `useSelector()` multiple times within a single function component.
57
57
### Equality Comparisons and Updates
58
58
59
59
When the function component renders, the provided selector function will be called and its result will be returned
60
-
from the `useSelector()` hook. (A cached result may be returned if the selector has been run and hasn't changed.)
60
+
from the `useSelector()` hook. (A cached result may be returned by the hook without re-running the selector if it's the same function reference as on a previous render of the component.)
61
61
62
62
However, when an action is dispatched to the Redux store, `useSelector()` only forces a re-render if the selector result
63
63
appears to be different than the last result. As of v7.1.0-alpha.5, the default comparison is a strict `===` reference
We recommend encapsulating any complex lookups or computations of data in selector functions. In addition, you can further optimize the performance by using [Reselect](https://github.com/reduxjs/reselect) to write “memoized” selectors that can skip unnecessary work. (See [the Redux docs page on Computing Derived Data](https://redux.js.org/recipes/computingderiveddata#sharing-selectors-across-multiple-components) and the blog post [Idiomatic Redux: Using Reselect Selectors for Encapsulation and Performance](https://blog.isquaredsoftware.com/2017/12/idiomatic-redux-using-reselect-selectors/) for more information on why and how to use selector functions.)
280
+
We recommend encapsulating any complex lookups or computations of data in selector functions. In addition, you can further optimize the performance by using [Reselect](https://github.com/reduxjs/reselect) to write “memoized” selectors that can skip unnecessary work. (See [the Redux docs page on Computing Derived Data](https://redux.js.org/recipes/computing-derived-data#sharing-selectors-across-multiple-components) and the blog post [Idiomatic Redux: Using Reselect Selectors for Encapsulation and Performance](https://blog.isquaredsoftware.com/2017/12/idiomatic-redux-using-reselect-selectors/) for more information on why and how to use selector functions.)
281
281
282
282
Now that our `<TodoList />` is connected to the store. It should receive the list of todos, map over them, and pass each todo to the `<Todo />` component. `<Todo />` will in turn render them to the screen. Now try adding a todo. It should come up on our todo list!
Copy file name to clipboardExpand all lines: docs/introduction/quick-start.md
+13-5
Original file line number
Diff line number
Diff line change
@@ -13,19 +13,27 @@ sidebar_label: Quick Start
13
13
14
14
React Redux 7.1 requires **React 16.8.3 or later.**
15
15
16
-
To use React Redux with your React app:
16
+
### Using Create React App
17
17
18
-
```bash
19
-
npm install react-redux
18
+
The recommended way to start new apps with React Redux is by using the [official Redux+JS template](https://github.com/reduxjs/cra-template-redux) for [Create React App](https://github.com/facebook/create-react-app), which takes advantage of [Redux Toolkit](https://redux-toolkit.js.org/).
19
+
20
+
```sh
21
+
npx create-react-app my-app --template redux
20
22
```
21
23
22
-
or
24
+
### An Existing React App
25
+
26
+
To use React Redux with your React app, install it as a dependency:
23
27
24
28
```bash
29
+
# If you use npm:
30
+
npm install react-redux
31
+
32
+
# Or if you use Yarn:
25
33
yarn add react-redux
26
34
```
27
35
28
-
You'll also need to [install Redux](https://redux-docs.netlify.com/introduction/installation) and [set up a Redux store](https://redux-docs.netlify.com/recipes/configuring-your-store) in your app.
36
+
You'll also need to [install Redux](https://redux.js.org/introduction/installation) and [set up a Redux store](https://redux.js.org/recipes/configuring-your-store/) in your app.
Copy file name to clipboardExpand all lines: docs/using-react-redux/accessing-store.md
+4
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,10 @@ by a single default context object instance generated by `React.createContext()`
26
26
React Redux's `<Provider>` component uses `<ReactReduxContext.Provider>` to put the Redux store and the current store
27
27
state into context, and `connect` uses `<ReactReduxContext.Consumer>` to read those values and handle updates.
28
28
29
+
## Using the `useStore` Hook
30
+
31
+
The [`useStore` hook](../api/hooks.md#useStore) returns the current store instance from the default `ReactReduxContext`. If you truly need to access the store, this is the recommended approach.
32
+
29
33
## Providing Custom Context
30
34
31
35
Instead of using the default context instance from React Redux, you may supply your own custom context instance.
0 commit comments