Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 authored and markerikson committed Oct 1, 2023
1 parent d248e7a commit 7cd3fd5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/api/actionCreatorMiddleware.mdx
Expand Up @@ -63,6 +63,6 @@ const actionCreatorMiddleware = createActionCreatorInvariantMiddleware({

const store = configureStore({
reducer,
middleware: new Tuple(actionCreatorMiddleware),
middleware: () => new Tuple(actionCreatorMiddleware),
})
```
28 changes: 11 additions & 17 deletions docs/api/configureStore.mdx
Expand Up @@ -100,18 +100,15 @@ If it is an object of slice reducers, like `{users : usersReducer, posts : posts

### `middleware`

An optional array of Redux middleware functions, or a callback to customise the array of middleware.
A callback which will receive `getDefaultMiddleware` as its argument,
and should return a middleware array.

If this option is provided, it should contain all the middleware functions you
If this option is provided, it should return all the middleware functions you
want added to the store. `configureStore` will automatically pass those to `applyMiddleware`.

If not provided, `configureStore` will call `getDefaultMiddleware` and use the
array of middleware functions it returns.

Where you wish to add onto or customize the default middleware,
you may pass a callback function that will receive `getDefaultMiddleware` as its argument,
and should return a middleware array.

For more details on how the `middleware` parameter works and the list of middleware that are added by default, see the
[`getDefaultMiddleware` docs page](./getDefaultMiddleware.mdx).

Expand All @@ -123,7 +120,7 @@ import { configureStore, Tuple } from '@reduxjs/toolkit'
configureStore({
reducer: rootReducer,
middleware: new Tuple(additionalMiddleware, logger),
middleware: () => new Tuple(additionalMiddleware, logger),
})
```

Expand Down Expand Up @@ -178,11 +175,6 @@ If you provide an array, this `applyMiddleware` enhancer will _not_ be used.
`configureStore` will warn in console if any middleware are provided (or left as default) but not included in the final list of enhancers.
```ts no-transpile
// warns - middleware left as default but not included in final enhancers
configureStore({
reducer,
enhancers: [offline(offlineConfig)],
})
// warns - middleware customised but not included in final enhancers
configureStore({
reducer,
Expand All @@ -199,8 +191,8 @@ configureStore({
// also allowed
configureStore({
reducer,
middleware: [],
enhancers: [offline(offlineConfig)],
middleware: () => [],
enhancers: () => [offline(offlineConfig)],
})
```

Expand All @@ -209,20 +201,22 @@ configureStore({
:::note Tuple
Typescript users are required to use a `Tuple` instance (if not using a `getDefaultEnhancer` result, which is already a `Tuple`), for better inference.

```
import { configureStore, Tuple } from '@reduxjs/toolkit'

configureStore({
reducer: rootReducer,
enhancers: new Tuple(offline),
enhancers: () => new Tuple(offline),
})

````
```
Javascript-only users are free to use a plain array if preferred.
:::
## Usage
### Basic Example
```ts
Expand All @@ -238,7 +232,7 @@ import rootReducer from './reducers'

const store = configureStore({ reducer: rootReducer })
// The store now has redux-thunk added and the Redux DevTools Extension is turned on
````
```
### Full Example
Expand Down
2 changes: 1 addition & 1 deletion docs/api/getDefaultMiddleware.mdx
Expand Up @@ -28,7 +28,7 @@ If you want to customize the list of middleware, you can supply an array of midd
```js
const store = configureStore({
reducer: rootReducer,
middleware: new Tuple(thunk, logger),
middleware: () => new Tuple(thunk, logger),
})

// Store specifically has the thunk and logger middleware applied
Expand Down
2 changes: 1 addition & 1 deletion docs/api/immutabilityMiddleware.mdx
Expand Up @@ -86,7 +86,7 @@ const immutableInvariantMiddleware = createImmutableStateInvariantMiddleware({
const store = configureStore({
reducer: exampleSliceReducer,
// Note that this will replace all default middleware
middleware: new Tuple(immutableInvariantMiddleware),
middleware: () => new Tuple(immutableInvariantMiddleware),
})
```

Expand Down
2 changes: 1 addition & 1 deletion docs/api/serializabilityMiddleware.mdx
Expand Up @@ -111,7 +111,7 @@ const serializableMiddleware = createSerializableStateInvariantMiddleware({

const store = configureStore({
reducer,
middleware: new Tuple(serializableMiddleware),
middleware: () => new Tuple(serializableMiddleware),
})
```

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/usage-with-typescript.md
Expand Up @@ -145,7 +145,7 @@ import { configureStore, Tuple } from '@reduxjs/toolkit'

configureStore({
reducer: rootReducer,
middleware: new Tuple(additionalMiddleware, logger),
middleware: () => new Tuple(additionalMiddleware, logger),
})
```

Expand Down

0 comments on commit 7cd3fd5

Please sign in to comment.