I want to render a static listing with cached HTML on initial page load using data that was fetched server side.
I do NOT want to display a loading indicator on initial page load. I want to display cached HTML data that was fetched on the server, not in browser.
HOWEVER I also want RTK Query to be able to handle updates to the list data if the list data is updated.
At the moment, I have this code:
app/discussions/page.tsx
import { DiscussionList } from '../components/DiscussionList'
export default async function DiscussionListPage() {
return <DiscussionList />
}
app/components/DiscussionList.tsx
export function DiscussionList() {
const { data, isFetching } = useFetchDiscussionsQuery()
if (isFetching) {
return <p>Loading...</p>
}
return (
<ul>
{data?.map((item) => (
<li key={item.discussionId}>
<h2>{item.title}</h2>
<p>{item.body}</p>
</li>
))}
</ul>
)
}
This displays a loading indicator in the static HTML at the moment, not prefetched data.
I need to change it so it renders list items on page load instead of the loading indicator.