Skip to content

Commit 2d3309d

Browse files
authored
Update Docusaurus to beta.0 and add "Learn Modern Redux" embed (#1724)
1 parent c136fb5 commit 2d3309d

20 files changed

+1764
-2706
lines changed

docs/api/Provider.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ id: provider
33
title: Provider
44
sidebar_label: Provider
55
hide_title: true
6+
description: 'API > Provider: providing the Redux store to your React app'
67
---
78

9+
 
10+
811
# `Provider`
912

1013
## Overview
@@ -30,13 +33,10 @@ You may provide a context instance. If you do so, you will need to provide the s
3033
>
3134
> Could not find "store" in the context of "Connect(MyComponent)". Either wrap the root component in a `<Provider>`, or pass a custom React context provider to `<Provider>` and the corresponding React context consumer to Connect(Todo) in connect options.
3235
33-
34-
3536
### Example Usage
3637

3738
In the example below, the `<App />` component is our root-level component. This means it’s at the very top of our component hierarchy.
3839

39-
4040
```jsx
4141
import React from 'react'
4242
import ReactDOM from 'react-dom'
@@ -54,4 +54,3 @@ ReactDOM.render(
5454
document.getElementById('root')
5555
)
5656
```
57-

docs/api/batch.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ id: batch
33
title: batch
44
sidebar_label: batch()
55
hide_title: true
6+
description: 'API > batch: batching React rendering updates'
67
---
78

9+
&nbsp;
10+
811
# `batch()`
912

1013
```js
1114
batch((fn: Function))
1215
```
1316

14-
*added in v7.0.0*
17+
_added in v7.0.0_
1518

1619
React's `unstable_batchedUpdates()` API allows any React updates in an event loop tick to be batched together into a single render pass. React already uses this internally for its own event handler callbacks. This API is actually part of the renderer packages like ReactDOM and React Native, not the React core itself.
1720

docs/api/connect-advanced.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ id: connect-advanced
33
title: connectAdvanced
44
sidebar_label: connectAdvanced()
55
hide_title: true
6+
description: 'API > connectAdvanced: customizing connect for advanced behavior'
67
---
78

9+
&nbsp;
10+
811
# `connectAdvanced()`
912

1013
```js
@@ -19,11 +22,10 @@ Most applications will not need to use this, as the default behavior in `connect
1922
2023
:::info
2124
22-
`connectAdvanced` was added in version 5.0, and `connect` was reimplemented as a specific set of parameters to `connectAdvanced`. However, [**`connectAdvanced` is now deprecated**](https://github.com/reduxjs/react-redux/issues/1236) and will eventually be removed in a future major version of React Redux.
25+
`connectAdvanced` was added in version 5.0, and `connect` was reimplemented as a specific set of parameters to `connectAdvanced`. However, [**`connectAdvanced` is now deprecated**](https://github.com/reduxjs/react-redux/issues/1236) and will eventually be removed in a future major version of React Redux.
2326
2427
:::
2528
26-
2729
## Arguments
2830
2931
- `selectorFactory(dispatch, factoryOptions): selector(state, ownProps): props` \(_Function_): Initializes a selector function (during each instance's constructor). That selector function is called any time the connector component needs to compute new props, as a result of a store state change or receiving new props. The result of `selector` is expected to be a plain object, which is passed as the props to the wrapped component. If a consecutive call to `selector` returns the same object (`===`) as its previous call, the component will not be re-rendered. It's the responsibility of `selector` to return that previous object when appropriate.

docs/api/connect.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ id: connect
33
title: Connect
44
sidebar_label: connect()
55
hide_title: true
6+
description: 'API > connect: a Higher-Order Component to interact with Redux'
67
---
78

9+
&nbsp;
10+
811
# `connect()`
912

1013
## Overview
@@ -116,7 +119,7 @@ The second parameter is normally referred to as `ownProps` by convention.
116119
117120
```js
118121
// binds on component re-rendering
119-
<button onClick={() => this.props.toggleTodo(this.props.todoId)} />
122+
;<button onClick={() => this.props.toggleTodo(this.props.todoId)} />
120123

121124
// binds on `props` change
122125
const mapDispatchToProps = (dispatch, ownProps) => ({
@@ -578,7 +581,6 @@ const makeMapState = (state) => {
578581
export default connect(makeMapState)(SomeComponent)
579582
```
580583
581-
582584
## Legacy Version Docs
583585
584586
While the `connect` API has stayed almost entirely API-compatible between all of our major versions, there have been some small changes in options and behavior from version to version.

docs/api/hooks.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ id: hooks
33
title: Hooks
44
sidebar_label: Hooks
55
hide_title: true
6+
description: 'API > Hooks: the `useSelector` and `useDispatch` hooks`'
67
---
78

9+
&nbsp;
10+
811
# Hooks
912

10-
React's new ["hooks" APIs](https://reactjs.org/docs/hooks-intro.html) give function components the ability to use local component state, execute side effects, and more. React also lets us write [custom hooks](https://reactjs.org/docs/hooks-custom.html), which let us extract reusable hooks to add our own behavior on top of React's built-in hooks.
13+
React's new ["hooks" APIs](https://reactjs.org/docs/hooks-intro.html) give function components the ability to use local component state, execute side effects, and more. React also lets us write [custom hooks](https://reactjs.org/docs/hooks-custom.html), which let us extract reusable hooks to add our own behavior on top of React's built-in hooks.
1114

12-
React Redux includes its own custom hook APIs, which allow your React components to subscribe to the Redux store and dispatch actions.
15+
React Redux includes its own custom hook APIs, which allow your React components to subscribe to the Redux store and dispatch actions.
1316

1417
:::tip
1518

@@ -107,7 +110,7 @@ import React from 'react'
107110
import { useSelector } from 'react-redux'
108111

109112
export const CounterComponent = () => {
110-
const counter = useSelector(state => state.counter)
113+
const counter = useSelector((state) => state.counter)
111114
return <div>{counter}</div>
112115
}
113116
```
@@ -118,8 +121,8 @@ Using props via closure to determine what to extract:
118121
import React from 'react'
119122
import { useSelector } from 'react-redux'
120123

121-
export const TodoListItem = props => {
122-
const todo = useSelector(state => state.todos[props.id])
124+
export const TodoListItem = (props) => {
125+
const todo = useSelector((state) => state.todos[props.id])
123126
return <div>{todo.text}</div>
124127
}
125128
```
@@ -136,8 +139,8 @@ import { useSelector } from 'react-redux'
136139
import { createSelector } from 'reselect'
137140

138141
const selectNumCompletedTodos = createSelector(
139-
state => state.todos,
140-
todos => todos.filter(todo => todo.completed).length
142+
(state) => state.todos,
143+
(todos) => todos.filter((todo) => todo.completed).length
141144
)
142145

143146
export const CompletedTodosCounter = () => {
@@ -163,14 +166,14 @@ import { useSelector } from 'react-redux'
163166
import { createSelector } from 'reselect'
164167

165168
const selectCompletedTodosCount = createSelector(
166-
state => state.todos,
169+
(state) => state.todos,
167170
(_, completed) => completed,
168171
(todos, completed) =>
169-
todos.filter(todo => todo.completed === completed).length
172+
todos.filter((todo) => todo.completed === completed).length
170173
)
171174

172175
export const CompletedTodosCount = ({ completed }) => {
173-
const matchingCount = useSelector(state =>
176+
const matchingCount = useSelector((state) =>
174177
selectCompletedTodosCount(state, completed)
175178
)
176179

@@ -196,16 +199,16 @@ import { createSelector } from 'reselect'
196199

197200
const makeSelectCompletedTodosCount = () =>
198201
createSelector(
199-
state => state.todos,
202+
(state) => state.todos,
200203
(_, completed) => completed,
201204
(todos, completed) =>
202-
todos.filter(todo => todo.completed === completed).length
205+
todos.filter((todo) => todo.completed === completed).length
203206
)
204207

205208
export const CompletedTodosCount = ({ completed }) => {
206209
const selectCompletedTodosCount = useMemo(makeSelectCompletedTodosCount, [])
207210

208-
const matchingCount = useSelector(state =>
211+
const matchingCount = useSelector((state) =>
209212
selectCompletedTodosCount(state, completed)
210213
)
211214

docs/introduction/getting-started.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
---
22
id: getting-started
3-
title: Getting Started
3+
title: Getting Started with React Redux
44
hide_title: true
55
sidebar_label: Getting Started
6+
description: 'Introduction > Getting Started: First steps with React Redux'
67
---
78

9+
&nbsp;
10+
11+
import LiteYouTubeEmbed from 'react-lite-youtube-embed';
12+
import 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css'
13+
814
# Getting Started with React Redux
915

1016
[React Redux](https://github.com/reduxjs/react-redux) is the official [React](https://reactjs.org/) UI bindings layer for [Redux](https://redux.js.org/). It lets your React components read data from a Redux store, and dispatch actions to the store to update state.
@@ -15,10 +21,14 @@ React Redux 7.1+ requires **React 16.8.3 or later**, in order to make use of Rea
1521

1622
### Using Create React App
1723

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/).
24+
The recommended way to start new apps with React and Redux is by using the [official Redux+JS template](https://github.com/reduxjs/cra-template-redux) or [Redux+TS template](https://github.com/reduxjs/cra-template-redux-typescript) for [Create React App](https://github.com/facebook/create-react-app), which takes advantage of **[Redux Toolkit](https://redux-toolkit.js.org/)** and React Redux's integration with React components.
1925

20-
```sh
26+
```bash
27+
# Redux + Plain JS template
2128
npx create-react-app my-app --template redux
29+
30+
# Redux + TypeScript template
31+
npx create-react-app my-app --template redux-typescript
2232
```
2333

2434
### An Existing React App
@@ -35,19 +45,19 @@ yarn add react-redux
3545

3646
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.
3747

38-
If you are using TypeScript, the React Redux types are maintained separately in DefinitelyTyped. You'll need to install those as well:
48+
If you are using TypeScript, the React Redux types are maintained separately in DefinitelyTyped, but included as a dependency of the `react-redux` package, so they should be installed automatically. If you still need to install them manually, run:
3949

4050
```bash
4151
npm install @types/react-redux
4252
```
4353

44-
The code used for this example is based on the [official Redux template](https://github.com/reduxjs/cra-template-redux). Additionally, the same code template for TypeScript can be found [here](https://github.com/reduxjs/cra-template-redux-typescript).
54+
## API Overview
4555

46-
## `Provider`
56+
### `Provider`
4757

4858
React Redux includes a `<Provider />` component, which makes the Redux store available to the rest of your app:
4959

50-
```js
60+
```jsx
5161
import React from 'react'
5262
import ReactDOM from 'react-dom'
5363

@@ -65,21 +75,21 @@ ReactDOM.render(
6575
)
6676
```
6777

68-
## Hooks
78+
### Hooks
6979

7080
React Redux provides a pair of custom React hooks that allow your React components to interact with the Redux store.
7181

7282
`useSelector` reads a value from the store state and subscribes to updates, while `useDispatch` returns the store's `dispatch` method to let you dispatch actions.
7383

74-
```js
84+
```jsx
7585
import React from 'react'
7686
import { useSelector, useDispatch } from 'react-redux'
7787
import {
7888
decrement,
7989
increment,
8090
incrementByAmount,
8191
incrementAsync,
82-
selectCount
92+
selectCount,
8393
} from './counterSlice'
8494
import styles from './Counter.module.css'
8595

@@ -112,6 +122,19 @@ export function Counter() {
112122
}
113123
```
114124

125+
## Learning React Redux
126+
127+
### Learn Modern Redux Livestream
128+
129+
Redux maintainer Mark Erikson appeared on the "Learn with Jason" show to explain how we recommend using Redux today. The show includes a live-coded example app that shows how to use Redux Toolkit and React-Redux hooks with Typescript, as well as the new RTK Query data fetching APIs.
130+
131+
See [the "Learn Modern Redux" show notes page](https://www.learnwithjason.dev/let-s-learn-modern-redux) for a transcript and links to the example app source.
132+
133+
<LiteYouTubeEmbed
134+
id="9zySeP5vH9c"
135+
title="Learn Modern Redux - Redux Toolkit, React-Redux Hooks, and RTK Query"
136+
/>
137+
115138
## Help and Discussion
116139

117140
The **[#redux channel](https://discord.gg/0ZcbPKXt5bZ6au5t)** of the **[Reactiflux Discord community](http://www.reactiflux.com)** is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - come join us!

docs/introduction/why-use-react-redux.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ id: why-use-react-redux
33
title: Why Use React Redux?
44
hide_title: true
55
sidebar_label: Why Use React Redux?
6+
description: 'Introduction > Why Use React Redux: benefits of using React Redux in a React app'
67
---
78

9+
&nbsp;
10+
811
# Why Use React Redux?
912

1013
Redux itself is a standalone library that can be used with any UI layer or framework, including React, Angular, Vue, Ember, and vanilla JS. Although Redux and React are commonly used together, they are independent of each other.

docs/troubleshooting.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ sidebar_label: Troubleshooting
55
hide_title: true
66
---
77

8+
&nbsp;
9+
810
## Troubleshooting
911

1012
The **[#redux channel](https://discord.gg/0ZcbPKXt5bZ6au5t)** of the **[Reactiflux Discord community](http://www.reactiflux.com)** is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - come join us!
1113

1214
You can also ask questions on [Stack Overflow](https://stackoverflow.com) using the **[#redux tag](https://stackoverflow.com/questions/tagged/redux)**.
1315

14-
1516
### My views aren’t updating!
1617

1718
In short,
1819

1920
- Reducers should never mutate state, they must return new objects, or React Redux won’t see the updates.
20-
- Make sure you are actually _dispatching_ actions. For example, if you have an action creator like `addTodo`, just calling the imported `addTodo()` function by itself won't do anything because it just _returns_ an action, but does not _dispatch_ it. You either need to call `dispatch(addTodo())` (if using the hooks API) or `props.addTodo()` (if using `connect` + `mapDispatch`).
21-
22-
21+
- Make sure you are actually _dispatching_ actions. For example, if you have an action creator like `addTodo`, just calling the imported `addTodo()` function by itself won't do anything because it just _returns_ an action, but does not _dispatch_ it. You either need to call `dispatch(addTodo())` (if using the hooks API) or `props.addTodo()` (if using `connect` + `mapDispatch`).
2322

2423
### Could not find "store" in either the context or props
2524

docs/tutorials/connect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ id: connect
33
title: 'Tutorial: Connect API'
44
hide_title: true
55
sidebar_label: 'Tutorial: Connect API'
6+
description: 'Tutorials > Connect API: how to use the legacy connect API'
67
---
78

9+
&nbsp;
10+
811
# Tutorial: Using the `connect` API
912

1013
:::tip
@@ -13,6 +16,8 @@ We now recommend using [the React-Redux hooks API as the default](../api/hooks.m
1316

1417
This tutorial also shows some older practices we no longer recommend, like separating Redux logic into folders by type. We've kept this tutorial as-is for completeness, but recommend reading through [the "Redux Essentials" tutorial](https://redux.js.org/tutorials/essentials/part-1-overview-concepts) and the [Redux Style Guide](https://redux.js.org/style-guide/style-guide) in the Redux docs for our current best practices.
1518

19+
We're working on a new tutorial that will introduce the hooks APIs. Until then, we suggest reading [**Redux Fundamentals, Part 5: UI and React**](https://redux.js.org/tutorials/fundamentals/part-5-ui-react) for a hooks tutorial.
20+
1621
:::
1722

1823
To see how to use React Redux in practice, we’ll show a step-by-step example by creating a todo list app.

0 commit comments

Comments
 (0)