小编gre*_*reg的帖子

Redux - mapDispatchToProps - TypeError: _this.props.setCurrentUserHandle 不是函数

我试图让一个简单的 react-redux 应用程序工作,但我遇到了一个我无法弄清楚的奇怪错误。我试图简单地设置我当前用户的名字并处理商店,一个设置功能有效,另一个无效。

setCurrentUserFirstName - 有效 setCurrentUserHandle - 没有

    import React, { Component } from 'react';
    从“反应路由器”导入{链接};
    从'react-redux'导入{连接};
    从“../../store”导入商店;
    var Utilities = require('../../../common/commonutilities.js');
    var RestClient = require('../../../common/restClient.js');

    //动作
    import { setCurrentUserHandle, setCurrentUserFirstName } from '../../actions/userActions';

    类头扩展组件{
      构造函数(道具){
        超级(道具);

        this.state = {};

        RestClient.api.fetchGet('/getcurrentuser', (response) => {
          如果(响应。成功){
            this.setState({
              isAuthenticated: 真,
              当前用户: response.currentUser
            });

            store.dispatch({
              类型:'USER_DID_LOGIN',
              用户登录:true
            });

            //工作正常
            this.props.setCurrentUserFirstName(response.currentUser.firstName);      

            //不起作用并抛出错误:“TypeError: _this.props.setCurrentUserHandle is not a function”
            this.props.setCurrentUserHandle(response.currentUser.handle);

          }
        },
        (错误)=> {
          控制台日志(错误);
        });
      }

      使成为() {
        返回 (
          

            {this.props.user.currentUserFirstName}, {this.props.user.currentUserHandle}

          

        );
      } …

reactjs redux react-redux

6
推荐指数
1
解决办法
1872
查看次数

标签 统计

react-redux ×1

reactjs ×1

redux ×1