一个典型的组件是这样的,我复制我的道具,是否有一个最好的做法,只为组件获得一次道具?而不是在submitForm()
class Screen3 extends Component {
constructor() {
super();
this.submitForm = this.submitForm.bind(this);
this.onChange = this.onChange.bind(this);
}
submitForm(e) {
const age = this.props.age;
const gender = this.props.gender;
const ethnicity = this.props.ethnicity;
....
}
onChange(e) {
const field = e.target.name;
const value = e.target.value;
...
}
render() {
let { age, gender, ethnicity } = this.props;
....
const mapStateToProps = store => {
return {
age: store.UserDetails.age,
gender: store.UserDetails.gender,
ethnicity: store.UserDetails.ethnicity
};
};