Using functional components, I need to fill an array with string Form data onSubmit. handleSubmit is supposed to store the string data but when I use console.log(value) it returns an empty array.
I can't figure out how to access the user input from the Form so that it can be stored into an array. I thought that setValue([value]) would be a method to accomplish this but clearly something is not right with my code.
read2List is supposed take the data from value and store it into an array when the submit button is clicked. I appreciate any ideas! Thank you for your time!
function App () {
const [value, setValue] = useState("");
const [entrylist, setEntry] = useState([]);
const handleSubmit = (event) => {
event.preventDefault();
setValue([value])
console.log(value)
}
const read2List = () => {
const updatedList = [...entrylist];
updatedList.push(value);
setEntry(updatedList);
console.log(updatedList);
}
return (
<div>
<div> Insert Entry </div>
<form class="entryForm" onSubmit={handleSubmit} >
<label for="newEntryId">
<span>New Entry:</span>
<textarea type="text" id="newEntryId" name="newEntryName" rows="30" cols="75" defaultValue = {"What's on your mind?"}
/>
</label>
<button type="submit" onClick={read2List}>Submit</button>
</form>
</div>
)
}
