FSA-compliant promise middleware for Redux (v0.6.0). It intercepts actions with a promise as the payload or the action itself as a promise. When the promise resolves, it dispatches a copy of the action with the resolved value and status 'success'; on rejection, it dispatches with the rejected value and status 'error'. The middleware returns a promise to the caller, useful for server-side rendering. It is part of the redux-utilities suite and works seamlessly with redux-actions. Built on the Flux Standard Action (FSA) spec, it requires actions to have a 'type' and optionally 'payload', 'error', and 'meta'. Compatible with all Redux versions. Stable, rarely updated, no known breaking changes since initial release.
npm install redux-promiseVerified import paths — ran on the pinned version, not inferred.
Demonstrates setup of Redux store with promiseMiddleware, a reducer handling the resolved action, and dispatching an async action with a promise payload.
For rejection handling, ensure the action payload is a promise and the action does not have 'error: true' initially (middleware sets it). Use try-catch in createAction or handle errors in reducer via 'status: error'.
Ensure all previous middleware in the chain return the value of next(action) (or next(action) itself) to propagate the promise.
If you relied on the initial dispatch (e.g., for loading state), add a separate loading action before the promise action.
Consider migrating to Redux Toolkit's createAsyncThunk or RTK Query for better async handling and TypeScript support.
Ensure you pass the middleware to createStore via applyMiddleware: createStore(reducer, applyMiddleware(promiseMiddleware))
Verify your action creator returns an object with 'type' and 'payload' set to a thenable (promise).
Either dispatch an action with promise payload, or use a different middleware like redux-thunk for direct promise dispatching.