Search code examples
htmlreactjsinputcontenteditablehtml-input

React editing input element that has a value


i have this input:

  <input
    type="text"
    autoFocus
    value={post.body}
   />

i want the user to be able to edit the value, i tried to set contentEditable but it doesn't work


Solution

  • <input type="text" autoFocus defaultValue={post.body}/>
    

    In your code, you can not edit value. Because you set value, so set defaultValue.