React redux调度器未连接



我有一个组件需要调用动作调度器,但当我触发它时,我得到了一个"未定义不是函数"的错误。

我使用的是react redux、redux persistent和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
});
};

我的组件.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未定义">

stack:"ReferenceError:updateProfile未定义在eval处(在CardInfo._this.handleUpdateProfile处的eval(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:151091:21),:1:1)位于Object.CardInfo._this.handleUpdateProfile[按onPress](blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:151091:21)在Object.Basic._this.handlePress[as-onPress](blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:124999:21)在Object.touchableHandlePress(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:46460:40)在对象处_performSideEffectsForTransition(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:45131:16)在对象处_receiveSignal(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:45060:14)在Object.touchableHandleResponderRelease(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:44939:12)在Object.invokeGuardedCallbackImpl(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:7899:16)在invokeGuardedCallback(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:7990:37)在invokeGuardedCallbackAndCatchFirstError(blob:http://localhost:8081/41e77cd1-d0f-413b-a32f-dfca9ee6061e:7994:31)">

AFAIK您应该将props作为参数添加到构造函数中。

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

相关内容

  • 没有找到相关文章

最新更新