Currently trying to refactor our project to use Server components (app directory), and the first challenge is how to implement infinite scroll pagination with new "app" directory.
This is an oversimplified page example:
import OrganisationInterface from "@/interfaces/OrganisationInterface";
async function getData() {
const res = await fetch('http://api.test/v1/organisations?page=1');
if (!res.ok) {
throw new Error('Failed to fetch data');
}
return res.json();
}
export default async function Page() {
const { data } = await getData();
return (
<>
<div className="mx-auto in-h-screen ">
{data && data.map((organisation: OrganisationInterface) => (
<div key={organisation.id}>
{organisation.attributes.title.lt}
</div>
))}
</div>
</>
);
}
I prefetch 10 initial results on the server, now I need to make client-side request to add another 10,20,30...
Or should I somehow do it on the server side? I need some ideas or examples of how to implement this correctly, previous solution was based on client-side exclusively, with SWR or ReactQuery.