hi I'm making a function that I can upload images to a server
my question is that after fetching I want to set fetching datas to a setstate but my fuction work without datas set.
is there a way to set fetcing datas before starting dispatch?
I've done some solutions it didn't work for me.
thanks for reading this question.
const uploadPostImage = async () => {
const url = `https://localhost:3000/somethingurl`;
const formData = new FormData();
formData.append("file", previewImage[0]);
formData.append("upload_preset", "something");
const response = await fetch(url, {
method: "post",
body: formData,
}).then();
const data = await response.json();
setNewPost((prev) => ({ ...prev, picture: data.public_id })); <-- **problem here**
dispatch(createPost(newPost));
};