I have a UserModal which is both used for insert and editing a user. On my <input>
element I have both specified the value
prop which uses the state and the defaultValue
prop which uses the username props if it is not null.
<input
type="text"
className="form-control"
id="username"
tabIndex={1}
required={true}
onChange={this.handleOnUsernameChange}
value={this.state.username}
defaultValue={this.props.username || ''} />
UserModal contains an input of type number with both value and defaultValue props. Input elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both). Decide between using a controlled or uncontrolled input element and remove one of these props.
If I use the <input>
element snippet from above then I get the warning/error message printed in the console. What are the best practices for handling situations where the default value is required with controlled component? Or is it easier/better to do this with an uncontrolled component?