[Dust] --- middleware --- Redux-promise-middleware --- [dust]

Source: Internet
Author: User
Tags redux middleware

I. Origins of Middleware

 

A single State is stored in the store. to update a state, you must first initiate an action (through the dispatch function). Action is equivalent to a Message notification, it is used to describe what happened (for example, adding a todo), and the reducer will update the state according to the action, so that the view can be rendered based on the new state.

 

Of course, the above is only the case of synchronous action,If action is asynchronous (for example, obtaining data from the server), the situation is different. You must use the Redux middleware.

 

Official explanation:Redux middleware is a third-party extension provided between initiating an action and reaching the reducer. The middleware is used between action and store. Dispatch.

 

Ii. Redux-promise

The payload attribute of the action of store. Dispatch can be placed on the promise object.

 

Usage:

(1) Introduction

Import {createstore, applymiddleware} from "Redux ";

Import promisemiddleware from "Redux-promise-Middleware ";

 

(2) Add Middleware

Const store = createstore (CER, applymiddleware (promisemiddleware ()))

 

(3) Compile asynchronous action in action

Note: This asynchronous action will pass two types. The first is add_item_pending, and the second is add_item_fulfilled. When add_item_pending is used, we can create a loding animation, when add_item_fulfilled is used, we can load the data to the page.

 

(4) use in components

 

 

Address: https://github.com/pburtchaell/redux-promise-middleware

[Dust] --- middleware --- Redux-promise-middleware --- [dust]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.