运行下面的代码时,我得到了错误。
TypeError: _this.props.signInUser is not a function
代码:
import {signInUser} from '../actions/authAction'
const mapStateToProps = (state) => ({
auth: state.auth,
errors: state.errors
});
const mapDispatchToProps = (dispatch) => ({
hideModal: modelType => dispatch(hideModal())
});
export default connect(
mapStateToProps,
mapDispatchToProps,
null,
{signInUser}
)(LoginModal);
非常感谢您的帮助。
答案 0 :(得分:2)
您没有正确将参数传递给connect
函数。要连接的第四个参数是options
,它在对象内采用以下值
{
context?: Object,
pure?: boolean,
areStatesEqual?: Function,
areOwnPropsEqual?: Function,
areStatePropsEqual?: Function,
areMergedPropsEqual?: Function,
forwardRef?: boolean,
}
和signInUser
不是其中之一。我想你的意思是将其传递给mapDisptachToProps
import {signInUser} from '../actions/authAction'
const mapStateToProps = (state) => ({
auth: state.auth,
errors: state.errors
});
const mapDispatchToProps = (dispatch) => ({
hideModal: modelType => dispatch(hideModal()),
signInUser: (...args) => dispatch(signInUser(...args));
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(LoginModal);