I have a server component in nextjs. I want to send a request to API to get data every time this page is loaded. that's why I apply { cache: 'no-store' }
to fetch and also
set revalidate to 0
, but It does not work. the first time It requests to API and in the second and third and .. does not
send request.
I think it fetches data from the cache.
NOTE
I added import 'server-only'
but does not affect it.
import 'server-only';
async function getPosts() {
const res = await fetch('http://localhost:4000/posts', { cache: 'no-store' })
return res.json()
}
export const revalidate = 0;
export default async function ServerPage() {
const posts = await getPosts()
return (
<div>
<h2>Server Props...</h2>
<ul>
{posts && posts.map(({ id, title, body }) => {
return (
<li key={id.toString()}>
<strong>{title}-{id}</strong>
<p>{body}</p>
</li>
)
})}
</ul>
</div>
)
}
How can I solve my problem ?