The UserForm which is controlled by another controller complains on console as
"Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components input span li ul..."**
This is the component code:
export default({user}) => {
if(!user) {
return <div></div>
} else {
const [name,setName] = useState(user.name|| "")
useEffect(() => {
setName(user.name);
}, [user])
return <form>
<fieldset>
<legend> Edit {user.name }</legend>
<p>
<label htmlFor={"name"}> Name </label>
<input id="name" value={name || ""} onChange={e => setName(e.target.value)} />
</p>
</fieldset>
</form>
}
}
I tried all fixes suggested on other stackoverflow answers but still gives warning.
Is there something I migth missing?