问题
<Field
defaultChecked={true}
onChange={this.handleFormItemRadio}
component={'input'}
type={'checkbox'}
name="tadmin" />
When the field is initialized, i expect it to be checked but it comes empty yet aim supplying in true
value.
poited to number of solutions but am still not able to solve this.
回答1:
According to the docs, the prescribed way is to set initialValues
<Field
onChange={this.handleFormItemRadio}
component='input'
type='checkbox'
name="tadmin" />
...
export default reduxForm({
form: 'simple', // a unique identifier for this form
initialValues: { tadmin: true },
})(SimpleForm);
Here's a CodeSandbox example
来源:https://stackoverflow.com/questions/54872817/react-redux-form-checkbox-defaultchecked-not-working