I have an issue where I think the existing state of a component is being posted via fetch before it has been updated.
This is the function called when submit is clicked:
function handleSubmit(e) {
e.preventDefault();
const html = convertToHTML(editorState.getCurrentContent());
setData((current) => [...current, { name: name, content: html }]);
fetch("/api2", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ parcel: data }),
});
}
I think data
is being posted before it has been updated via setData
.
How do I get the POST
method to action after data
has been updated?