Input field is read-only

Hi all - I’m new to react and web dev in general. I have created a Box with a FormField inside. It displays correctly but I cannot seem to enter any text in the input field. It is not taking any values, like it is read-only. Does anyone know what I am doing wrong? Here is my code:

                    label= {formLabel}
                        placeholder = {descriptionPlaceHolder}
                        value = {addDescription}
                        onChange={e => addDescription =}                            
                        style = {{marginTop: 10}}
                        onClick = {() => {}}

Try taking the button out of the form field, I think form fields only support one child element (your input).

Thanks Kamille - I have tried that already and it has the same result. The field remains inactive.

Solved it - I do not yet quite understand the state and how react deals with it. You have to tajke the onChange via the state, So adding a useState and setState solved it for me:

const [descript, setdescript] = useState("");

onChange={e => setdescript(}

1 Like

In React controls such as inputs should normally be “controlled”. That means that there is always a value kept in state (through the useState hook) that is passed to the value of the input. This model of always rendering your data in a single direction makes things easy to reason about your app once it grows. For instance you can use the value somewhere else, and it isn’t just locked in your input, for instance:

const [value, setValue] = useState('');

return (
            onChange={e => setValue(}                            
         <p>Here is your value always in sync: {value}</p>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.