Skip to content

Commit 4d74ce2

Browse files
authored
Docs: Various punctuation adjustments, remove duplicate examples, update serializable middleware signature (#994)
1 parent 8a6845a commit 4d74ce2

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

docs/api/serializabilityMiddleware.mdx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ interface SerializableStateInvariantMiddlewareOptions {
5353
* Defaults to 32ms.
5454
*/
5555
warnAfter?: number
56+
57+
/**
58+
* Opt out of checking state, but continue checking actions
59+
*/
60+
ignoreState?: boolean
5661
}
5762
```
5863

@@ -69,7 +74,7 @@ Example:
6974
```ts
7075
// file: reducer.ts noEmit
7176

72-
export default function(state = {}, action: any) {
77+
export default function (state = {}, action: any) {
7378
return state
7479
}
7580

@@ -79,7 +84,7 @@ import { Iterable } from 'immutable'
7984
import {
8085
configureStore,
8186
createSerializableStateInvariantMiddleware,
82-
isPlain
87+
isPlain,
8388
} from '@reduxjs/toolkit'
8489
import reducer from './reducer'
8590

@@ -92,12 +97,12 @@ const getEntries = (value: any) =>
9297

9398
const serializableMiddleware = createSerializableStateInvariantMiddleware({
9499
isSerializable,
95-
getEntries
100+
getEntries,
96101
})
97102

98103
const store = configureStore({
99104
reducer,
100-
middleware: [serializableMiddleware]
105+
middleware: [serializableMiddleware],
101106
})
102107
```
103108

docs/tutorials/typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export type AppDispatch = typeof store.dispatch
6565
6666
### Define Typed Hooks
6767
68-
While it's possible to import the `RootState` and `AppDispatch` types into each component, it's **better to create typed versions of the `useDispatch` and `useSelector` hooks for usage in your application**. . This is important for a couple reasons:
68+
While it's possible to import the `RootState` and `AppDispatch` types into each component, it's **better to create typed versions of the `useDispatch` and `useSelector` hooks for usage in your application**. This is important for a couple reasons:
6969
7070
- For `useSelector`, it saves you the need to type `(state: RootState)` every time
7171
- For `useDispatch`, the default `Dispatch` type does not know about thunks. In order to correctly dispatch thunks, you need to use the specific customized `AppDispatch` type from the store that includes the thunk middleware types, and use that with `useDispatch`. Adding a pre-typed `useDispatch` hook keeps you from forgetting to import `AppDispatch` where it's needed.

docs/usage/usage-guide.md

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Every Redux app needs to configure and create a Redux store. This usually involv
2424
- Importing or creating the root reducer function
2525
- Setting up middleware, likely including at least one middleware to handle asynchronous logic
2626
- Configuring the [Redux DevTools Extension](https://github.com/zalmoxisus/redux-devtools-extension)
27-
- Possibly altering some of the logic based on whether the application is being built for development or production.
27+
- Possibly altering some of the logic based on whether the application is being built for development or production
2828

2929
### Manual Store Setup
3030

@@ -66,7 +66,7 @@ This example is readable, but the process isn't always straightforward:
6666

6767
`configureStore` helps with those issues by:
6868

69-
- Having an options object with "named" parameters, which can be easier to read.
69+
- Having an options object with "named" parameters, which can be easier to read
7070
- Letting you provide arrays of middleware and enhancers you want to add to the store, and calling `applyMiddleware` and `compose` for you automatically
7171
- Enabling the Redux DevTools Extension automatically
7272

@@ -144,7 +144,7 @@ If you provide the `middleware` argument, `configureStore` will only use whateve
144144
[Reducers](https://redux.js.org/basics/reducers) are the most important Redux concept. A typical reducer function needs to:
145145

146146
- Look at the `type` field of the action object to see how it should respond
147-
- Update its state immutably, by making copies of the parts of the state that need to change and only modifying those copies.
147+
- Update its state immutably, by making copies of the parts of the state that need to change and only modifying those copies
148148

149149
While you can [use any conditional logic you want](https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-2/#switch-statements) in a reducer, the most common approach is a `switch` statement, because it's a straightforward way to handle multiple possible values for a single field. However, many people don't like switch statements. The Redux docs show an example of [writing a function that acts as a lookup table based on action types](https://redux.js.org/recipes/reducing-boilerplate#generating-reducers), but leave it up to users to customize that function themselves.
150150

@@ -385,8 +385,8 @@ export default function postsReducer(state = initialState, action) {
385385

386386
The only truly necessary part here is the reducer itself. Consider the other parts:
387387

388-
- We could have written the action types as inline strings in both places.
389-
- The action creators are good, but they're not _required_ to use Redux - a component could skip supplying a `mapDispatch` argument to `connect`, and just call `this.props.dispatch({type : "CREATE_POST", payload : {id : 123, title : "Hello World"}})` itself.
388+
- We could have written the action types as inline strings in both places
389+
- The action creators are good, but they're not _required_ to use Redux - a component could skip supplying a `mapDispatch` argument to `connect`, and just call `this.props.dispatch({type : "CREATE_POST", payload : {id : 123, title : "Hello World"}})` itself
390390
- The only reason we're even writing multiple files is because it's common to separate code by what it does
391391

392392
The ["ducks" file structure](https://github.com/erikras/ducks-modular-redux) proposes putting all of your Redux-related logic for a given slice into a single file, like this:
@@ -482,23 +482,6 @@ console.log(createPost({ id: 123, title: 'Hello World' }))
482482

483483
`createSlice` looked at all of the functions that were defined in the `reducers` field, and for every "case reducer" function provided, generates an action creator that uses the name of the reducer as the action type itself. So, the `createPost` reducer became an action type of `"posts/createPost"`, and the `createPost()` action creator will return an action with that type.
484484

485-
```js
486-
const postsSlice = createSlice({
487-
name: 'posts',
488-
initialState: [],
489-
reducers: {
490-
createPost(state, action) {},
491-
updatePost(state, action) {},
492-
deletePost(state, action) {},
493-
},
494-
})
495-
496-
const { createPost } = postsSlice.actions
497-
498-
console.log(createPost({ id: 123, title: 'Hello World' }))
499-
// {type : "posts/createPost", payload : {id : 123, title : "Hello World"}}
500-
```
501-
502485
### Exporting and Using Slices
503486

504487
Most of the time, you'll want to define a slice, and export its action creators and reducers. The recommended way to do this is using ES6 destructuring and export syntax:
@@ -616,7 +599,7 @@ const fetchUsers = () => async (dispatch) => {
616599

617600
Data fetching logic for Redux typically follows a predictable pattern:
618601

619-
- A "start" action is dispatched before the request, to indicate that the request is in progress. This may be used to track loading state to allow skipping duplicate requests or show loading indicators in the UI.
602+
- A "start" action is dispatched before the request to indicate that the request is in progress. This may be used to track loading state, to allow skipping duplicate requests, or show loading indicators in the UI.
620603
- The async request is made
621604
- Depending on the request result, the async logic dispatches either a "success" action containing the result data, or a "failure" action containing error details. The reducer logic clears the loading state in both cases, and either processes the result data from the success case, or stores the error value for potential display.
622605

@@ -1037,7 +1020,7 @@ One of the core usage principles for Redux is that [you should not put non-seria
10371020

10381021
However, like most rules, there are exceptions. There may be occasions when you have to deal with actions that need to accept non-serializable data. This should be done very rarely and only if necessary, and these non-serializable payloads shouldn't ever make it into your application state through a reducer.
10391022

1040-
The [serializability dev check middleware](../api/getDefaultMiddleware.mdx) will automatically warn anytime it detects non-serializable values in your actions or state. We encourage you to leave this middleware active to help avoid accidentally making mistakes. However, if you _do_ need to turnoff those warnings, you can customize the middleware by configuring it to ignore specific action types, or fields in actions and state:
1023+
The [serializability dev check middleware](../api/serializabilityMiddleware.mdx) will automatically warn anytime it detects non-serializable values in your actions or state. We encourage you to leave this middleware active to help avoid accidentally making mistakes. However, if you _do_ need to turnoff those warnings, you can customize the middleware by configuring it to ignore specific action types, or fields in actions and state:
10411024

10421025
```js
10431026
configureStore({

0 commit comments

Comments
 (0)