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)

 

 



posted @ 2016-05-30 17:17  Rella  阅读(185)  评论(0编辑  收藏  举报