Gathering detailed insights and metrics for redux-await-action
Gathering detailed insights and metrics for redux-await-action
Gathering detailed insights and metrics for redux-await-action
Gathering detailed insights and metrics for redux-await-action
redux-async-await-action-middleware
Redux middleware to enable async/await action creators
redux-async-await
redux middleware to es7 async/await syntax action and promise action
@moxy/redux-await-actions
Waits for specific actions to be dispatched or a timeout expires.
redux-mock-store-await-actions
Waits for specific actions to be dispatched or a timeout expires.
Library to listen for redux actions in react components and handling logic based on the dispatched action.
npm install redux-await-action
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (75.02%)
JavaScript (24.98%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
10 Commits
2 Forks
1 Watchers
1 Branches
3 Contributors
Updated on Jun 28, 2023
Latest Version
1.0.2
Package Id
redux-await-action@1.0.2
Unpacked Size
51.67 kB
Size
24.69 kB
File Count
33
NPM Version
6.14.16
Node Version
12.22.12
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
44
A redux extension to wait for actions in react components Requires the installation of react (>= 16.3) and redux (>= 4)
If using redux, sometimes there is a need to wait with specific logic until an action is dispatched. This is especially needed when decoupling ajax requests from react components with redux-observable or redux-thunk into asynchronous actions.
npm i --save redux-await-action
You need to create an instance of the event emitter and apply the middleware to your redux store.
1import { createAwaitMiddleware, StoreAwaitEventEmitter } from 'redux-await-action'; 2 3const awaitEmitter = new StoreAwaitEventEmitter(); 4const storeAwaitMiddleware = createAwaitMiddleware(awaitEmitter); 5 6const store = createReduxStore( 7 rootReducer, 8 applyMiddleware(storeAwaitMiddleware) 9);
To be able to wait for actions inside the react components, you need to add the StoreAwaitProvider in your JSX. It should be placed somewhere near your redux store provider.
1import { Provider } from 'redux'; 2import { StoreAwaitProvider } from 'redux-await-action'; 3 4return ( 5 <Provider store={store}> 6 <StoreAwaitProvider emitter={awaitEmitter}> 7 {props.children} 8 </StoreAwaitProvider> 9 </Provider> 10);
useAwaitAction()
hook1import React from 'react'; 2import { connect, DispatchProp } from 'redux'; 3import { useAwaitAction } from 'redux-await-action'; 4 5export const myCoponent = connect()((props: DispatchProp) => { 6 const awaitAction = useAwaitAction(); 7 8 const handleLoadData = () => { 9 /** 10 * This statement creates a promise that resolves when an action with type 'LOAD_DATA_SUCCEEDED' is dispatched. 11 * If 'LOAD_DATA_FAILED' is dispatched earlier, the promise will reject 12 */ 13 awaitAction('LOAD_DATA_SUCCEEDED', 'LOAD_DATA_FAILED').then(() => { 14 window.location.href = 'https://example.org/data-loaded'; 15 }); 16 17 // This dispatches a redux action (is redux functionality). 18 // The action should be async (using something like redux-observable) and dispatch 'LOAD_DATA_SUCCEEDED' when the data is successfully loaded. 19 dispatch({ type: 'LOAD_DATA_START' }); 20 }; 21 22 return ( 23 <button onClick={handleLoadData}> 24 Click Me! 25 </button> 26 ); 27});
withAwaitAction()
HOCClass based components can't use React hooks. So there needs to be an other way to inject the awaitAction
method.
1import React, { Component } from 'react'; 2import { connect, DispatchProp } from 'redux'; 3import { withAwaitAction, WithAwaitAction } from 'redux-await-action'; 4 5class MyCoponent extends Component<DispatchProp & WithAwaitAction> { 6 private handleLoadData = () => { 7 /** 8 * This statement creates a promise that resolves when an action with type 'LOAD_DATA_SUCCEEDED' is dispatched. 9 * If 'LOAD_DATA_FAILED' is dispatched earlier, the promise will reject 10 */ 11 props.storeAwait('LOAD_DATA_SUCCEEDED', 'LOAD_DATA_FAILED').then(() => { 12 window.location.href = 'https://example.org/data-loaded'; 13 }); 14 15 // This dispatches a redux action (is redux functionality). 16 // The action should be async (using something like redux-observable) and dispatch 'LOAD_DATA_SUCCEEDED' when the data is successfully loaded. 17 dispatch({ type: 'LOAD_DATA_START' }); 18 }; 19 20 public render() { 21 return ( 22 <button onClick={handleLoadData}> 23 Click Me! 24 </button> 25 ); 26 } 27} 28 29export default withAwaitAction(connect()(MyComponent));
The await method that is created from the hook or passed from the HOC takes 1 - 2 arguments.
The first argument is the type of the action that needs to be dispatched in the happy case - so when the returne promise should resolve.
The second argument ts the type of the action that needs to be dispatched when the returned promise should reject.
Both arguments can either be a string (one action type) or an array containing multiple action types.
If one of the arguments is an array, the promise will resolve or reject at the first action that contains one of the passed types.
The method returns a promise.
The returned promise will be resolved when one of the action types of the first parameter is dispatched. The promise resolves whith the dispatched action.
So the dispatched action that made the promise resolve is passed to the then
callback.
The returned promise will be rejected when one of the action types of the second parameter is dispatched. The promise rejects the dispatched action.
So the dispatched action that made the promise reject is passed to the catch
callback.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/10 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
39 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More