我收到此错误,“TypeError:调度不是函数”我做错了什么?我已阅读 redux 的文档,但我看不出我做错了什么? (redux初学者)故障出在inputIsValid方法
import React from 'react';
import { connect } from 'react-redux';
import { validatedAuthInput } from '../actions/index';
class AuthInput extends React.Component {
constructor(props) {
super(props);
this.state = { inputValue: '' };
}
inputIsValid({ dispatch }, value) {
dispatch(validatedAuthInput(this.props.type, value));
this.validInput(this.props.type, value);
return value.includes('@') && value.length > 4 ? 'success' : 'warning';
}
handleinput = event => {
this.setState({ inputValue: event.target.value });
};
render() {
return (
<FormGroup
label={this.props.label}
validationState={this.inputIsValid(this.state.inputValue)}>
<ControlLabel>{this.props.label}</ControlLabel>
<FormControl
type={this.props.type}
value={this.state.value}
placeholder={this.props.placeholder}
onChange={this.handleinput}
/>
<FormControl.Feedback />
</FormGroup>
);
}
}
export default connect(null)(AuthInput);
最佳答案
Props 不会自动传递到该函数中,因此您需要在函数内执行 this.props
。我建议您将操作与组件分开,并将 mapDispatchToProps
对象传递给 connect
as described here
关于javascript - 类型错误 : dispatch is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48390534/