nextjs how to render serverside and then update data client-side based on a filter?

I have this page.tsx rendering on the server:
const PostsPage = async () => {
const posts = await db.post.findMany({
take: 25,
include: {
author: true
}
});

return (
<div>
<div>
<label>Filter verified posts</label>
<input type="checkbox" ... /> // checkbox to filter posts (add query string?)
</div>

<div>
{posts.map(p => (<Post
key={p.id}
id={p.id}
content={p.content}
authorName={p.author.name}
/>))}
</div>
</div>
);
};
const PostsPage = async () => {
const posts = await db.post.findMany({
take: 25,
include: {
author: true
}
});

return (
<div>
<div>
<label>Filter verified posts</label>
<input type="checkbox" ... /> // checkbox to filter posts (add query string?)
</div>

<div>
{posts.map(p => (<Post
key={p.id}
id={p.id}
content={p.content}
authorName={p.author.name}
/>))}
</div>
</div>
);
};
2 Replies
ibby
ibbyOP14mo ago
I guess I could take in params, get query string and do db call based on that but then the checkbox would be unchecked?
NotLuksus
NotLuksus14mo ago
yeah query params might be the easiest here, for the checkbox you can just use something like ?filter=true no?

Did you find this page helpful?