Asked 2 months ago
0 Answers
1 Views
I want to fetch this data every time the user accesses the route so that the data is always fresh. Below is a simple example. I think it's not possible.
I have tried:
export const revalidate = 0;
export const dynamic = 'force-dynamic';
export const fetchCache = 'force-no-store';
cache: 'no-store'
I want to use SSR but I also need the data to be dynamic as it changes a lot and the user should see fresh data each time the access the route.
// app/test/page.tsx
import React from "react";
export const revalidate = 0;
export const dynamic = 'force-dynamic';
export const fetchCache = 'force-no-store';
interface User {
id: number;
name: string;
username: string;
email: string;
}
export default async function UsersPage() {
console.log('Fetching users...');
const response = await fetch('https://jsonplaceholder.typicode.com/users', {
cache: 'no-store',
});
if (!response.ok) {
console.error('Error fetching users:', response.statusText);
return <div>Error fetching users: {response.statusText}</div>;
}
const data: User[] = await response.json();
console.log('Fetched users:', data);
return (
<div>
<h1>Users</h1>
{data.length ? (
<ul>
{data.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
) : (
<p>No users found</p>
)}
</div>
);
}
0 Answers