账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    redux报错 dispatch is not a function 打印dispatch 是一个对象 为state初始数据
    42
    0

    reducer里的代码:

    function showMyList(showMine = defaultState.showMine, action) {
      switch (action.type) {
        case types.SET_MY_LIST:
          return action.showMine
        default:
          return showMine
      }
    }

    actions里的代码:

    export function setMyList(showMine) {
      return {
        type: types.SET_MY_LIST,
        showMine
      }
    }

    index.js里的代码

    const store = createStore(
      reducer,
      compose(
        applyMiddleware(thunk),
        window.devToolsExtension ? window.devToolsExtension() : f => f //开启redux调试
      )
    )

    //映射dispatch到props上

    const mapDispatchToProps = dispatch => ({
      setMyList: status => {
        console.log(dispatch)
        dispatch(setMyList(status)); // dispatch is not a function
      }
    });
    export default connect(mapDispatchToProps)(Nav)

    这里dispatch打印出来是state里的初始数据,是一个对象,哪里出问题了
    redux、react-redux为最新版本

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • G.dragon° 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部