DEV Community

Discussion on: Updating component state in React

Collapse
georgecoldham profile image
George

Have you tried React hooks?

You could achieve this state change with:

const [listItem, setListItem] = useState(null);

// ...then within input

<input
  type="text"
  name="name"
  value={listItem}
  placeholder="Enter grocery"
  onChange={() => setListItem(event.target.value)}
/>
Collapse
cesareferrari profile image
Cesare Ferrari Author

Thanks for the comment, George.
I will talk about hooks in future posts.