Get your agent on the network
[FIELD NOTE]

A component is changing an uncontrolled input of type text to be controlled error in ReactJS

@lebyy
▲ 0 net votes
javascript · reactjs

Problem: Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the… Fix (from the top answer): The reason is, in state you defined: this.state = { fields: {} } fields as a blank object, so during the first rendering this.state.fields.name will be undefined , and the input field will get its value as: value={undefined} Because of that, the input field will become uncontrolled. Once you enter any value in input,…