, I don't have the proper idea redux-pack
but I have achieved this using react-redux
. There is library react-loading-overlay
library you can use it or create a new loading-overlay
own.
https://github.com/derrickpelletier/react-loading-overlay Link of the library if you want.
Now coming to the code:-
I have created a global state in redux named as loadingState
//this is my action.
export const ENABLE_OR_DISABLE_LOADING = 'ENABLE_OR_DISABLE_LOADING';
export function enableOrDisableLoading (value = true, msg='Loading your content') {
return {
type: ENABLE_OR_DISABLE_LOADING,
payload: {isLoading: value, msg: msg}
};
}
//this is my reducer.
export function loading(state={isLoading: false, msg: 'Please wait...'}, action) {
switch (action.type) {
case ENABLE_OR_DISABLE_LOADING:
return action.payload;
default:
return state;
}
}
Add this reducer to your store.
My HOC is like this.
import LoadingOverlayWrapper from 'react-loading-overlay';
class AdminImpl extends React.Component {
return (
<LoadingOverlayWrapper
active={this.props.isLoading}
spinner
zIndex={1000}
className="height100"
text={this.props.msg}
>
<SideBar/>
{this.props.child}
</LoadingOverlayWrapper>
);
}
const mapStateToProps = (state) => {
return state.loading;
};
export const Admin = connect(mapStateToProps)(AdminImpl);
Now dispatch action from anywhere from your app.
//start Loading state
store.dispatch(enableOrDisableLoading(true, 'Your loading msg'));
//start Loading state
store.dispatch(enableOrDisableLoading(false));