V
V
vintalis2021-11-28 20:06:34
React
vintalis, 2021-11-28 20:06:34

How to update NEXTJS post data after page reload?

Page [id].jsx

In it I generate information
export async function getStaticProps({ params }) {
  const res = await fetch(`api`);
  const data = await res.json();
  return {
    props: {
      post: data
    },
    revalidate: 1,
  }
}
export async function getStaticPaths() {
  const res = await fetch('api');
  const allpost = await res.json();
  return {
    paths: allpost?.data.map(({ id }) => `/stocks/${id}`),
    fallback: 'blocking'
  }


But there is a problem that after updating the post, the data is not updated immediately, so you need to update the page 2 times so that the page is with new data.
But I would like to get the same effect as with getServerSideProps, after refreshing the page, the data changed immediately. As I understand it, these are NEXTJS properties, how to bypass them or change something ..

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question