r/learnreactjs • u/Sea-Men69 • Jan 10 '23
Question Checkbox, when checked dissapears after refresh and not saved in DB.
My checkbox is marking a noteid but whenever page is refreshed the checkbox vanishes. Also it's never saved to the database for some reason. Any ideas?
Part of the relevant code. ( full code in comments)
<div className="Data-flex" key={data.noteId}>
<div className="NoteID" style={{ flex: 1 }}>
{data.noteId}
</div>
<Checkbox
style={{ flex: 1 }}
onChange={handleStatus}
Function Below!
const [Status2, setStatus2] = useState(false);
const handleStatus = (event, data) => {
console.log("Marking todo ... Data : ", data);
setStatus2(true);
};
View all comments
Show parent comment
1
u/Sea-Men69 Jan 12 '23
I recieved this code from chatGTP ai, so it should update the database but still doesn't and whenever refreshing the page it isn't marked anymore.
const handleStatus = (event, data) => {
console.log("Marking todo ... Data : ", data);
setStatus2(!Status2); // toggle the status
toDoListServices
.UpdateNote({...data, status: Status2})
.then((data) => {
console.log("Data : ", data);
setSnackMessage(data.data.message);
setOpenSnackBar(true);
GetNotes(PageNumber, Data.Sortvalue);
GetNotes("");
})
.catch((error) => {
console.log("Error : ", error);
});
};