π«
π«
π«
π«
Promise Middleware
GitHub
StackOverflow
npm
Searchβ¦
Introduction
Getting Started
Introduction
Design Principles
Guides
Catching Errors Thrown by Rejected Promises
Chaining Actions
Comparison to other promise middleware
Custom Type Delimiters
Custom Types
Optimistic Updates
Use with Async/Await
Use with Reducers
Use with Redux Actions
Use with Redux Promise Actions
Use with Promises Resolved with Null Values
Upgrade Guides
Upgrade from 5.x to 6.0.0
Upgrade from 4.x to 5.0.0
Upgrade from 3.x to 4.0.0
Release History
Powered By
GitBook
Introduction
Installation
First, install the middleware.
1
npm i redux-promise-middleware -s
Copied!
Setup
Import the middleware and include it in
applyMiddleware
when creating the Redux store:
1
import
promise
from
'redux-promise-middleware'
2
β
3
composeStoreWithMiddleware
=
applyMiddleware
(
4
promise
,
5
)(
createStore
)
Copied!
Use
Dispatch a promise as the value of the
payload
property of the action.
1
const
foo
=
()
=>
({
2
type
:
'FOO'
,
3
payload
:
new
Promise
()
4
});
Copied!
A pending action is immediately dispatched.
1
{
2
type
:
'FOO_PENDING'
3
}
Copied!
Once the promise is settled, a second action will be dispatched. If the promise is resolved a fulfilled action is dispatched.
1
{
2
type
:
'FOO_FULFILLED'
3
payload
:
{
4
...
5
}
6
}
Copied!
On the other hand, if the promise is rejected, a rejected action is dispatched.
1
{
2
type
:
'FOO_REJECTED'
3
error
:
true
,
4
payload
:
{
5
...
6
}
7
}
Copied!
That's it!
Further Reading
β
Catching Errors Thrown by Rejected Promises
β
β
Use with Reducers
β
β
Optimistic Updates
β
β
Design Principles
β
Copyright (c) 2017 Patrick Burtchaell.
Code licensed with the MIT License (MIT)
.
Documentation licensed with the CC BY-NC License
.
Previous
Introduction
Next - Getting Started
Design Principles
Last modified
3yr ago
Copy link
Contents
Installation
Setup
Use
Further Reading