Add first content on redux middleware (#18643)
* Add first content on redux middleware Add a description of what redux middleware is, some examples of what it can be used for, and how to add it to your app. * fix: formatting
This commit is contained in:
@ -3,13 +3,26 @@ title: Redux Middleware
|
||||
---
|
||||
## Redux Middleware
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/redux/redux-middleware/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
One of the great things about redux is that it provides an interface to plug in different middleware packages to add additional functionality to redux. Redux middleware basically acts like pipes that your actions will flow through after getting dispatched but before being handled by your reducers. There are a large amount of popular redux middleware packages for adding features like logging and handling asynchronous action flows.
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
[Redux Thunk](https://github.com/reduxjs/redux-thunk) for example allows you to dispatch functions to delay the dispatching of actions.
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
Adding middleware to redux is as simple as adding another argument when calling "createStore". Just pass the result of calling "applyMiddleware" with each middleware package you want to use. In the example below we add redux-thunk and redux-logger to our app.
|
||||
|
||||
```js
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import logger from 'redux-logger'
|
||||
|
||||
const store = createStore(
|
||||
rootReducer,
|
||||
applyMiddleware(thunk, logger)
|
||||
);
|
||||
```
|
||||
|
||||
#### More Information:
|
||||
<!-- Please add any articles you think might be helpful to read before writing the article -->
|
||||
[Middleware - Redux docs](https://redux.js.org/advanced/middleware)
|
||||
|
||||
|
||||
[Redux Logger](https://github.com/evgenyrodionov/redux-logger)
|
||||
[Redux Thunk](https://github.com/reduxjs/redux-thunk)
|
||||
|
Reference in New Issue
Block a user