Skip to content

Commit ee80685

Browse files
authored
Merge branch 'master' into fix-layout-effect-race-condition
2 parents 58a964c + 79f3d13 commit ee80685

File tree

8 files changed

+59
-16
lines changed

8 files changed

+59
-16
lines changed

README.md

Lines changed: 20 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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/introduction/basic-tutorial.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ 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

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

Lines changed: 4 additions & 0 deletions
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.

src/components/connectAdvanced.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ export default function connectAdvanced(
272272
const usePureOnlyMemo = pure ? useMemo : callback => callback()
273273

274274
function ConnectFunction(props) {
275-
const [propsContext, forwardedRef, wrapperProps] = useMemo(() => {
275+
const [
276+
propsContext,
277+
reactReduxForwardedRef,
278+
wrapperProps
279+
] = useMemo(() => {
276280
// Distinguish between actual "data" props that were passed to the wrapper component,
277281
// and values needed to control behavior (forwarded refs, alternate context instances).
278282
// To maintain the wrapperProps object reference, memoize this destructuring.
279-
const { forwardedRef, ...wrapperProps } = props
280-
return [props.context, forwardedRef, wrapperProps]
283+
const { reactReduxForwardedRef, ...wrapperProps } = props
284+
return [props.context, reactReduxForwardedRef, wrapperProps]
281285
}, [props])
282286

283287
const ContextToUse = useMemo(() => {
@@ -437,8 +441,13 @@ export default function connectAdvanced(
437441
// Now that all that's done, we can finally try to actually render the child component.
438442
// We memoize the elements for the rendered child component as an optimization.
439443
const renderedWrappedComponent = useMemo(
440-
() => <WrappedComponent {...actualChildProps} ref={forwardedRef} />,
441-
[forwardedRef, WrappedComponent, actualChildProps]
444+
() => (
445+
<WrappedComponent
446+
{...actualChildProps}
447+
ref={reactReduxForwardedRef}
448+
/>
449+
),
450+
[reactReduxForwardedRef, WrappedComponent, actualChildProps]
442451
)
443452

444453
// If React sees the exact same element reference as last time, it bails out of re-rendering
@@ -472,7 +481,7 @@ export default function connectAdvanced(
472481
props,
473482
ref
474483
) {
475-
return <Connect {...props} forwardedRef={ref} />
484+
return <Connect {...props} reactReduxForwardedRef={ref} />
476485
})
477486

478487
forwarded.displayName = displayName

src/hooks/useSelector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function useSelectorWithStoreAndSubscription(
7070
latestSubscriptionCallbackError.current = err
7171
}
7272

73-
forceRender({})
73+
forceRender()
7474
}
7575

7676
subscription.onStateChange = checkForUpdates

website/versioned_docs/version-7.2/using-react-redux/accessing-store.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ propagated to connected components, so that this works as expected by default.
1818
However, there may be certain use cases where you may need to customize how the store and state are propagated to
1919
connected components, or access the store directly. Here are some examples of how to do this.
2020

21+
## Using the `useStore` Hook
22+
23+
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.
24+
2125
## Understanding Context Usage
2226

2327
Internally, React Redux uses [React's "context" feature](https://reactjs.org/docs/context.html) to make the

0 commit comments

Comments
 (0)