簡體   English   中英

React-Redux調度程序未連接

[英]React-redux dispatcher not being connected

我有一個需要調用動作分派器的組件,但是當我觸發它時,出現“未定義不是函數”錯誤。

我正在使用react-redux,redux-persist和redux-thunk。

我的所有其他動作在調用時都可以正常工作。

UserActions.js

export const updateProfile = (user, token) => {
  return async dispatch => {
    try {
      axios()
        .then(response => {
          getUpdateProfileSuccess(response.data, dispatch);
        })
        .catch(error => {
          getUpdateProfileError(error.response, dispatch);
        });
    } catch (error) {
      getUpdateProfileError(error.response, dispatch);
    }
  };
};

const getUpdateProfileSuccess = (data, dispatch) => {
  dispatch({
    type: UPDATE_PROFILE_SUCCESS,
    data
  });
};

const getUpdateProfileError = (error, dispatch) => {
  dispatch({
    type: UPDATE_PROFILE_ERROR,
    error
  });
};

我的component.js

import...
import { updateProfile } from "../../../../Actions/UserActions";

class CardInfo extends Component {
  _handleUpdateProfile = () => {
    let user = {...};
    this.props.updateProfile(user, this.props.token);
  }
  render() {
    return (...)
  }
}

const mapStateToProps = state => ({
  token: state.UserReducer.token,
  user_data: state.UserReducer.user_data
});

export default connect(
  mapStateToProps,
  { updateProfile }
)(CardInfo);

當我調試代碼時,出現此錯誤:

消息:“未定義updateProfile”

堆棧:“ ReferenceError:未在eval處定義updateProfile(在CardInfo._this._handleUpdateProfile處為eval(blob: http:// localhost:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6061e:151091:21,: 1:1)在Object.Basic._this._handlePress [在onPress]上位於Object.CardInfo._this._handleUpdateProfile [按onPress](blob: http:// localhost:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6061e:151091:21 ) Blob: http:// localhost:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6061e:124999:21 )at Object.touchableHandlePress(blob: http:// localhost:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6061e:46460 :40 )at Object._performSideEffectsForTransition(blob: http:// localhost:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6061e:45131:16 )at Object._receiveSignal(blob: http:// localhost:8081 / 41e77cd1-d0ff -413b-a32f-dfca9ee6061e:45060:14 )位於Object.invokeGuardedCallbackImpl(blob: http:/http:// localhost:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6061e:44939:12/本地主機:8081 / 41e77cd1-d0ff-413b-a32f-dfca9ee6 061e:7899:16在invokeGuardedCallback)(BLOB: HTTP://本地主機:8081 / 41e77cd1-d0ff-413B-A32F-dfca9ee6061e:7990:37 )在invokeGuardedCallbackAndCatchFirstError(BLOB: HTTP://本地主機:8081 / 41e77cd1-d0ff- 413b-a32f-dfca9ee6061e:7994:31 )“

AFAIK,您應該將props作為參數添加到構造函數。

class CardInfo extends Component {
  constructor(props) {
    super(props);
  }
  ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM