Answer the question
In order to leave comments, you need to log in
Why do we need redux-thunk?
Why do we need redux-thunk?
I looked at a course on Redux, where an example of working with asynchronous code using thunk was given , but why is it needed if the same code can be described without it?
Here is an example with thunk:
//...
const asyncIncrementHandler = () => {
return (dispatch) => {
setTimeout(() => {
dispatch({type: 'ASYNC_INCREMENT'})
}, 5000);
}
}
//...
<Button onClick={() => {
dispatch(asyncIncrementHandler())
}}>ASYNC INCREMENT</Button>
//...
//...
const asyncIncrementHandler = (dispatch) => {
setTimeout(() => {
dispatch({type: 'ASYNC_INCREMENT'})
}, 5000);
}
//...
<Button onClick={() => {
asyncIncrementHandler(dispatch)
}}>ASYNC INCREMENT</Button>
//...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question