I recently started experimenting with Vercel's SWR, and I must say it seems like the most suitable library for data fetching in Next.js. However, I've encountered some challenges while trying to integrate it with TypeScript.
Referring to the instructions in the documentation on pagination using SWRInfinite, I attempted to implement an infinite loader as shown below:
const { data, error, isValidating, mutate, size, setSize } = useSWRInfinite(
getKey, fetcher?, options?
)
Unfortunately, I received error messages stating:
Property 'size' does not exist on type 'SWRResponse<any, any>'.ts(2339)
Property 'setSize' does not exist on type 'SWRResponse<any, any>'.ts(2339)
All the parameters appear to be in place except for the last two. What could I be overlooking here? Interestingly, everything works perfectly fine when TypeScript is not being used. I have ensured that both Next.js and SWR are updated to their latest versions. Despite my efforts to follow the provided guidelines and include the getKey function, the issue persists.
Any helpful suggestions?