I have <InputLabel>
and Select
and MenuItem
components used in the code as follows:
<div className="form-field full-width-field ">
<InputLabel>Q3.Is this the correct data?</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={''}
onChange={handleChange}
>
<MenuItem value={'Y'}>Yes</MenuItem>
<MenuItem value={'N'}>No</MenuItem>
</Select>
</div>
So, when I use value = {''}
as shown above in the Select
, I don't see any error in the code. However, when a user selects Yes
or No
, nothing is displayed on the screen, as shown below:
However, when I comment out the value = {''}
part and use it like this:
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
//value={''}
onChange={handleChange}
>
It displays the user selection Yes
or No
on the screen but I keep getting following warning in the console i nred color:
Warning: A component is changing an uncontrolled input of type undefined 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 component.
How can I fix both the issues?