#How do I do fetching and caching properly in Next13 + Sanity app?

3 messages · Page 1 of 1 (latest)

visual dust
#

Hi, everyone.

I have an Next13 (with app dir) + Sanity app, and I would like to prevent hitting the Sanity endpoint on every client request. However, I'm not sure If I have set it up correctly.

I have a dynamic segment /lessons/[lessonId]/page.tsx and i use the next-sanity client to fetch data. In the build report, it says that these pages are SSG.

Here is this page, I render a "lesson". Each lesson has an array of "sessions". I want to filter each session on button clicks. Right now, I do that by useSearchParams and setting params with router.push in a "use client"-component.

It works, but when user click filter buttons, the page fetches on each click. My questions are:

  1. Is this because the segment page itself is a server component?
  2. Will each of these fetches hit the Sanity endpoint as well?

I appreciate all inputs.

daring terrace
#

I can't give you a solid answer on this, but I can say that I've noticed that data fetching seems to occur more often than the docs would imply

#

in other words, it looks like some aspects of caching aren't fully implemented