Я использую antd
дизайн в своей форме.
Здесь я устанавливаю значение из редуктора profilereducer
, используя метод shouldComponentUpdate
.
class ProfileForm extends Component {
componentDidMount = () => {
this.props.actions.getprofile()
}
shouldComponentUpdate = (nextProps) => {
if (this.props.profile) {
this.props.form.setFieldsValue({
name: this.props.profile.name,
});
} else {
this.props.form.setFieldsValue({
firstname: 'loading',
});
}
}
render() {
const { getFieldDecorator, getFieldValue } = this.props.form;
<Form layout="vertical">
<FormItem label="First Name" >
{getFieldDecorator('name', { rules: [{ required: true, message: 'Required!', }], })(
<Input addonBefore={selectBefore} placeholder="First Name" />
)}
</FormItem>
</Form>
}
function mapStateToProps(state) {
return {
profile: state.profilereducer.profile,
}
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch)
}
}
const Profile = Form.create()(ProfileForm);
export default connect(mapStateToProps, mapDispatchToProps)(Profile);
}
Ошибка: