I am creating a custom input to handle a toggle switch.
Form component
<Field
label='Link to individuals'
name='employeeLink'
value={true}
component={Switch}
/>
If I log this.props.input.value
of the Switch component I get value: ""
. How do I pass the initial value
as seen in the form component to the Switch? Updating the value works as expected.
Or do I need to call componentDidMount
as below? If yes, will it not always be dirty?
componentDidMount() {
this.props.input.onChange(this.props.input.value);
}
Totally forgot that redux-form provides a way to pass initial values
See:
http://redux-form.com/6.4.3/examples/initializeFromState/ http://redux-form.com/6.4.3/docs/api/ReduxForm.md/#-initialvalues-object-string-string-optional-