【发布时间】:2019-10-13 03:19:50
【问题描述】:
我正在尝试使用 Redux Form 字段为我的 Select 标签设置一个初始值。
Redux 字段:
<Field
name="statusDto.pkid"
component={renderSelectField}
type="text"
isHidden="true"
placeholder="Select Status"
options={userRegistrationStatus && userRegistrationStatus.map((values) => { return ({ value: values.pkid, label: i18next.languages[0] === 'en' ? values.enName : values.trName }); })}
/>
Redux 表单:
UserRegistrationForm = reduxForm({
validate,
form: 'User_Registration_Form', // a unique identifier for this form
enableReinitialize: true,
})(UserRegistrationForm));
反应选择:
handleChange = (selectedOption) => {
const { onChange } = this.props;
this.setState({ selectedOptionState: selectedOption });
onChange(selectedOption.value);
};
<Select
name={name}
value={selectedOptionState}
onChange={this.handleChange}
styles={customStyles}
options={options}
clearable={false}
className="react-select"
placeholder={placeholder}
isDisabled={isDisabled}
classNamePrefix="react-select"
theme={(theme) => ({
...theme,
borderRadius: 0,
colors: {
...theme.colors,
primary: '#70bbfd',
},
})}
/>
使用 redux-form 初始化,我尝试将第一个值分配给 react-select,但这似乎不值得。你能帮帮我吗?
【问题讨论】:
标签: reactjs redux-form react-select