Please give me solution I am creating a app similar to Google keep. As soon as I click add button is add to array after that it refreshes the page and array value resets
Here's my Code
import React, { useState } from "react";
function CreateArea() {
const [title1, setTitle1] = useState([]);
const [note1, setNote1] = useState([]);
function Changed(event) {
const a = event.target.name;
// const b=event.target.name;
if (a === "title") {
// console.log("hello")
setTitle1(event.target.value);
} else {
// console.log("note")
setNote1(event.target.value);
}
}
function addNote() {
// setTitle1((prevValue) => {
// return [...prevValue, title1]
// })
// console.log(titleCont)
setNote1("");
setTitle1("");
console.log(title1);
}
return (
<div>
<form>
<input
name="title"
onChange={Changed}
placeholder="Title"
// value={title1}
/>
<textarea
name="content"
onChange={Changed}
placeholder="Take a note..."
// value={note1}
rows="3"
/>
<button onClick={addNote}>Add</button>
</form>
</div>
);
}
export default CreateArea;
IDK if this code if sufficient or not if need more of my code plz tell me i will add more