Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
how to update states after fetching in react

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));
  };
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!