使用NextJS中的GetServersideProps获取更新的数据
因此,我有一个公共页面,我在NextJ中使用getServersideProps进行了预先渲染。现在,一旦我对页面中的数据进行了更新,直到我重新构建之前,新的更新才显示。请如何处理?
例如,假设我有一个博客文章页面:“ https://example.com/blog/what-is-stackoverflow”。在此页面中,我通过对数据库进行API调用来获取一些图片。现在,我已经通过另一个API从2到3更新了图片的数量。 在再次访问该特定博客页面时,我只看到2张图片,而不是最新更新中的3张图片。但是,如果我重建下一个JS网站,我现在可以看到这3张图片。
这是代码的副本:
export const getServerSideProps = async ({ params }) => {
const { data: professionalData } = await client.query({
query: GET_PROFESSIONAL,
variables: {
uuid: params.uuid,
},
});
return {
props: {
data: professionalData.user,
},
};
};
谢谢你等待回复
So, I have a public page which I am pre-rendering using getServerSideProps in Nextjs. Now, once I make updates to the data in the page, the new updates do not show until I re-build. Please how do I handle this?
As an example, let's say I have a blog post page: "https://example.com/blog/what-is-stackoverflow". In this page I am fetching some pictures by making an api call to a database. I have now updated the number of pictures through another api from let's say 2 to 3.
On visiting that particular blog page again, I am only seeing 2 pictures instead of 3 from the most recent update. But if I rebuild my next-js website, I now get to see the 3 pictures.
Here is a copy of the code:
export const getServerSideProps = async ({ params }) => {
const { data: professionalData } = await client.query({
query: GET_PROFESSIONAL,
variables: {
uuid: params.uuid,
},
});
return {
props: {
data: professionalData.user,
},
};
};
Thank you as I await a response
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论