1.redux
redux-thunk
1.安装
npm i redux-thunk --save
2.引入
import thunk from "redux-thunk"
let store=createStore(reducer,composeWithDevTools(applyMiddleware(thunk)))
3.使用
//actionCreator
export const actions = {
changeName: (name) => ({
type: TYPES.TEST_CHANGE_NAME,
name
}),
changeAge: age => ({
type: TYPES.TEST_CHANGE_AGE,
age
}),
delayChangeName: name => {
return (dispatch,getState)=>{
setTimeout(() => {
dispatch(actions.changeName(name))
}, 1000)
}
}
}