Thunk
Redux Thunk
npm i -s redux-thunk
Redux out of the box does not the thing to do async.
Thunk is a function that’s returned from another function.
function definitelyNotAThunk() {
return function aThunk() {
console.log("Hello, I'm thunk");
}
}
- Regular Action Creator
export const getAllItems = () => ({
type: UPDATE_ALL_ITEMS,
items,
})
- Thunking Abstraction
export const getAllItems = () => ({
return dispatch => {
Api.getAll().then(items => {
dispatch({
type: UPDATE_ALL_ITEMS,
items,
})})}})