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

248
Views
Why data is not updating in NextJS?

I wondering why data is not updating while I make DELETE request? Should I change getServerSideProps to getStaticProps or there is other way how to solve this problem? In addition I don't want to reload page :)

const Component = ({ data }) => {

  return (
    <div>
      {data.map((el) => {
        return (
          <React.Fragment key={el._id}>
            <span>{el.visitorDate}</span>
            <span>{el.visitorName}</span>
            <span>{el.visitorFamilyName}</span>
            <div>
              <button
                onClick={async () => {
                  const res = await fetch(
                    `http://localhost:4000/api/visitorData/${el._id}`,
                    {
                      method: "DELETE",
                      headers: {
                        "Content-Type": "application/json",
                      },
                    }
                  );
                }}
              >
                DELETE
              </button>
            </div>
          </React.Fragment>
        );
      })}
    </div>
  );
};

export default Component;

export async function getServerSideProps(context) {
  const res = await fetch("http://localhost:4000/api/visitorData/");
  const data = await res.json();
  return {
    props: { data },
  };
}

If something is unclear, let me know :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to update the data after the DELETE request to see your changes.

Either handle this manually in onClick, or add router.refresh() after the fetch.

about 4 years ago · Juan Pablo Isaza Report
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!