Skip to content

Commit 7d20db4

Browse files
committed
Merge branch 'master' into use-tracked-state
2 parents c01ddc0 + 2a5b12b commit 7d20db4

33 files changed

+3214
-223
lines changed

.github/ISSUE_TEMPLATE/---bug-report.md

-24
This file was deleted.

.github/ISSUE_TEMPLATE/---support-usage-question.md

-10
This file was deleted.

.github/ISSUE_TEMPLATE/Bug_report.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: "\U0001F41B Bug report"
3+
about: Something isn't working correctly.
4+
5+
---
6+
<!--
7+
Thank you for contributing to open source!
8+
9+
Do you need some help?
10+
======================
11+
12+
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?
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: 👍 Feature Request
3+
about: I'd like React Redux to do something new.
4+
---
5+
6+
<!--
7+
Thank you for contributing to open source!
8+
9+
Do you need some help?
10+
======================
11+
12+
The issue tracker is meant for feature requests and bug reports only. This isn't the best place for
13+
support or usage questions. Questions here don't have as much visibility as they do elsewhere. Before
14+
you ask a question, here are some resources to get help first:
15+
16+
- Read the docs: https://react-redux.js.org/
17+
- Check out the troubleshooting guide: https://react-redux.js.org/troubleshooting
18+
- Look for/ask questions on Stack Overflow: https://stackoverflow.com/questions/tagged/redux
19+
- Ask in chat: https://www.reactiflux.com/
20+
21+
Have a feature request?
22+
=======================
23+
Remove the template from below and provide thoughtful commentary *and code samples* on what this
24+
feature means for your product. What will it allow you to do that you can't do today? How will it
25+
make current work-arounds straightforward? What potential bugs and edge cases does it help to
26+
avoid? etc. Please keep it product-centric.
27+
28+
-->
29+
30+
## New Features
31+
32+
### What is the new or updated feature that you are suggesting?
33+
34+
### Why should this feature be included?
35+
36+
### What docs changes are needed to explain this?

.github/ISSUE_TEMPLATE/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: 🤔 Questions and Help
4+
url: https://redux.js.org/introduction/getting-started#help-and-discussion
5+
about: This is a bug tracker, not a support system. For usage questions, please use our support resources.

.github/workflows/main.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Compressed Size
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2-beta
11+
with:
12+
fetch-depth: 1
13+
- uses: preactjs/compressed-size-action@v1
14+
with:
15+
repo-token: '${{ secrets.GITHUB_TOKEN }}'

README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@ Performant and flexible.
1111

1212
## Installation
1313

14-
React Redux requires **React 16.8.3 or later.**
14+
### Using Create React App
1515

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
1620
```
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
1834
```
1935

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+
2038
This assumes that you’re using [npm](http://npmjs.com/) package manager
2139
with a module bundler like [Webpack](https://webpack.js.org/) or
2240
[Browserify](http://browserify.org/) to consume [CommonJS

docs/api/connect.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ The second parameter is normally referred to as `ownProps` by convention.
124124
<button onClick={() => this.props.toggleTodo(this.props.todoId)} />
125125

126126
// binds on `props` change
127-
const mapDispatchToProps = (dispatch, ownProps) => {
127+
const mapDispatchToProps = (dispatch, ownProps) => ({
128128
toggleTodo: () => dispatch(toggleTodo(ownProps.todoId))
129-
}
129+
})
130130
```
131131
132132
The number of declared function parameters of `mapDispatchToProps` determines whether they receive ownProps. See notes [here](#the-arity-of-maptoprops-functions).

docs/api/hooks.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ From there, you may import any of the listed React Redux hooks APIs and use them
3333
## `useSelector()`
3434

3535
```js
36-
const result : any = useSelector(selector : Function, equalityFn? : Function)
36+
const result: any = useSelector(selector: Function, equalityFn?: Function)
3737
```
3838

3939
Allows you to extract data from the Redux store state, using a selector function.
4040

4141
> **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.
4242
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.
4444

4545
However, there are some differences between the selectors passed to `useSelector()` and a `mapState` function:
4646

@@ -57,7 +57,7 @@ You may call `useSelector()` multiple times within a single function component.
5757
### Equality Comparisons and Updates
5858

5959
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.)
6161

6262
However, when an action is dispatched to the Redux store, `useSelector()` only forces a re-render if the selector result
6363
appears to be different than the last result. As of v7.1.0-alpha.5, the default comparison is a strict `===` reference

docs/introduction/basic-tutorial.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ const TodoList = // ... UI component implementation
277277
export default connect(state => ({ todos: getTodos(state) }))(TodoList);
278278
```
279279

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/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.)
281281

282282
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!
283283

docs/introduction/quick-start.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@ sidebar_label: Quick Start
1313

1414
React Redux 7.1 requires **React 16.8.3 or later.**
1515

16-
To use React Redux with your React app:
16+
### Using Create React App
1717

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
2022
```
2123

22-
or
24+
### An Existing React App
25+
26+
To use React Redux with your React app, install it as a dependency:
2327

2428
```bash
29+
# If you use npm:
30+
npm install react-redux
31+
32+
# Or if you use Yarn:
2533
yarn add react-redux
2634
```
2735

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.
2937

3038
## `Provider`
3139

docs/using-react-redux/accessing-store.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ by a single default context object instance generated by `React.createContext()`
2626
React Redux's `<Provider>` component uses `<ReactReduxContext.Provider>` to put the Redux store and the current store
2727
state into context, and `connect` uses `<ReactReduxContext.Consumer>` to read those values and handle updates.
2828

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+
2933
## Providing Custom Context
3034

3135
Instead of using the default context instance from React Redux, you may supply your own custom context instance.

docs/using-react-redux/connect-dispatching-actions-with-mapDispatchToProps.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ render() {
159159
}
160160

161161
const mapDispatchToProps = dispatch => {
162-
toggleTodo: todoId => dispatch(toggleTodo(todoId))
162+
return {
163+
toggleTodo: todoId => dispatch(toggleTodo(todoId))
164+
}
163165
}
164166
```
165167

@@ -171,7 +173,9 @@ render() {
171173
}
172174

173175
const mapDispatchToProps = (dispatch, ownProps) => {
174-
toggleTodo: () => dispatch(toggleTodo(ownProps.todoId))
176+
return {
177+
toggleTodo: () => dispatch(toggleTodo(ownProps.todoId))
178+
}
175179
}
176180
```
177181

0 commit comments

Comments
 (0)