鍍金池/ 問答/HTML/ .dispatch is not a function

.dispatch is not a function

組件1:

const mapDispatchToProps = (dispatch) => {
  return {
    currency: (data) => dispatch(currency(data)),
  }
}
const mapStateToProps = (state) => {
  return ({
      changeContent: state.changeContent
    }
  )
}


handleClick = (e, special) => {
    const { changeContent } = this.props;
    changeContent({type:'CHANGE',item:e.key})

};
export default connect((state, ownProps) => {
    return {
      menuList: state.menuList,
      userInfor: state.userInfor,
      menuKeys: state.menuKey,
      language: state.language,
    };
  }, mapStateToProps,
  mapDispatchToProps)(Container);

組件2:

//CommonList組件

render (){
    return (
        <div>{this.props.changeContent}</div>
)}
const changeContent =(state)=>({
    changeContent:state.changeContent
})
export default connect(changeContent)( Form.create({})(CommonList))

reducer:

const changeContent =  (state = [], action) =>{
  switch (action.type){
    case "CHANGE" :
      return ([...state, action.item])
    default:
      return state
  }
}
export default changeContent

運(yùn)行就會(huì)報(bào)錯(cuò),changeContent is not a function

clipboard.png

回答
編輯回答
久礙你

你的Container這個(gè)組件里面確實(shí)沒有this.props.changeContent呀,你要不是通過外面使用傳過去<Container changeContent={...} />, 要不就在mapDispatchToProps = (dispatch) => ({ changeContent: function})

2017年3月12日 03:49
編輯回答
厭遇

你這樣用不對(duì),changeContent是一個(gè)reducer,你是想執(zhí)行一個(gè)action直接使用
this.props.dispatch({type:'CHANG',item}),另外你的
const mapDispatchToProps = (dispatch) => {
return dispatch
}
就不會(huì)提示dispatch is not a function

2017年10月31日 21:51