using redux thunk code example
Example 1: redux thunk
npm install redux-thunk
Example 2: redux-thunk example
const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
function increment() {
return {
type: INCREMENT_COUNTER
};
}
function incrementAsync() {
return dispatch => {
setTimeout(() => {
// You can invoke sync or async actions with `dispatch`
dispatch(increment());
}, 1000);
};
}