Only update when the component is visible? #502
-
I have a component in my Next.js app which uses Is there a way I can make I've already looked at |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
hi @akshatmittal swr doesn't listen to DOM change or visible. and the hidden in so I think you can use Intersection_Observer_API to track the visibility of your hidden component, or you know the timestamp exactly when component slides into screen. then you can call or you can wrap your useSWR hook in a standalone component, which only renders when your component becomes visible to users. hope this can solve part of the problem. |
Beta Was this translation helpful? Give feedback.
hi @akshatmittal swr doesn't listen to DOM change or visible. and the hidden in
refreshWhenHidden
represents the visibility of current page/browser tab instead of some specific component.so I think you can use Intersection_Observer_API to track the visibility of your hidden component, or you know the timestamp exactly when component slides into screen. then you can call
mutate()
orrevalidate()
to update state from swr.or you can wrap your useSWR hook in a standalone component, which only renders when your component becomes visible to users. hope this can solve part of the problem.