redux-async
RSA-compliant actions which resolve when any prop is a promise middleware for Redux.
Install
npm install --save redux-async
Adding as middleware
;let createStoreWithMiddleware = createStore;
Usage
// action-creators.jsconst loadUsersForAdmin = { return types: GET_USERS_REQUEST GET_USERS_SUCCESS GET_USERS_FAILURE payload: users: api adminId ;} // reducers.js;; const initialState = {}; initialState { const adminId = actionpayload; return isFetching: true adminId // we always have access to all non promise properties ; } { const adminId users = actionpayload; return isFetching: false users // all promise properties resolved adminId // we always have access to all non promise properties - same as above ; } { // assert(action.error === true && action.payload instanceof Error); // when a property gets rejected then the non promise properties go in the meta object // assert(action.meta.adminId); return errorMessage: actionpayloadmessage; // from Error.prototype.message }; // smart-container.js// ... snipped to the middle of the render function<div> !users ? <button onClick= >Load Users</button> : isFetching ? <span>isFetching for adminId...</span> : <pre>JSON</pre> errorMessage && <div className="error">errorMessage</div> </div>