Looking to get some guidance on the correct approach to pass props from a client component to a server component in NextJS 14 app router.
My use case:
I have a current Page.tsx in the root of /app that is a server component (default) and is fetching data from a Xata DB (SDK). I current have a search bar using searchParams within that same file to query the data in the URL "q?="
const xata = getXataClient();
export default async function Card({ searchParams }: { searchParams: { q: string } }) {
let cards = null;
if (searchParams.q) {
const { records } = await xata.db.Network.search(searchParams.q, {
fuzziness: 1,
boosters: [{ valueBooster: { column: 'PremiumMember', value: true, factor: 5 } }]
}
);
cards = records;
} else {
cards = await xata.db.Network.filter({ProfileActive: true}).getMany({
pagination: { size: 24 },
fetchOptions: { next: { revalidate: "60" } },
});
}
This obviously works fine but does not feel "fast".
In order to search you have to hit enter to send the q request to the server and back. This causes a page refresh which also scrolls the users potentially elsewhere. Although still fairly quick it does not feel instant like other examples I've seen generally.
I'm wondering if refactoring this search bar out to a client component and passing down the q props to the page file would yield a "snappier" searching experience? This is stretching some of my React/NextJS knowledge but the leap I'm making is that since the Page.tsx data was fetched on the server, then it should be cached for the page session. Thus allowing the passed client search props to filter already cached data. Therefore snappy?
I may be missing a few links here. Would appreciate any guidance on if/how this pattern is supposed to work 🙏