I'm trying to have the data from the textarea in the form be stored in an array once the user hits the submit button. I'm working with only functional components. Do I need to use preventDefault() to stop the page from refreshing in order for the data to be transferred into an array? I need the form to still clear after the user hits submit so if I use preventDefault() I will likely need to create a new component to reset the textarea.
I appreciate any ideas! Thank you for your time!
function App () {
const [value, setValue] = useState("");
const [entrylist, setEntry] = useState([]);
const handleChange = () => {
setValue([value])
console.log(value)
}
const readNWrite = () => {
setEntry([entrylist])
entrylist.push(value)
}
return (
<div>
<div> Insert Entry </div>
<form class="entryForm" >
<label for="newEntryId">
<span>New Entry:</span>
<textarea type="text" id="newEntryId" name="newEntryName" rows="30" cols="75" defaultValue = {"What's on your mind?"} onChange={(e)=> {
handleChange(e.target.value);
}} />
</label>
<button onClick={readNWrite}>Submit</button>
</form>
</div>
)
}