dispatch a action with a timeout
程序入口文件添加依赖:
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
// actions.js
const hideTip = (dispatch) => {
setTimeout(() => {
dispatch(setTip(""))
}, 1000)
}
const showTipWithTimeout = (tip) => {
return function(dispatch) {
dispatch(setTip(tip))
hideTip(dispatch)
}
}
export default showTipWithTimeout
//component.js加入
onShowTipWithTimeout: (tip) => {
dispatch(actions.showTipWithTimeout(tip))
}
//调用
othes.onShowTipWithTimeout(string)