How to Store Textarea Text in a useState Hook in React.js

Published Jan 29, 2022  ∙  Updated May 2, 2022

How can we store our textarea text in a useState() hook?

It’s quite simple to target the value stored in the textarea using event.target.value. We can then pass it into our set function.

import React, { useState } from "react";
export const TextArea = () => {
  const [message, setMessage] = useState("");
  return (
    <textarea 
      name="message"
      value={message} 
      onChange={e => setMessage(e.target.value)}>
    </textarea>
  )
}