Next.js Discord

Discord Forum

SWR: Auto revalidating every 4 minutes, but only when is focused

Unanswered
Scottish Fold posted this in #help-forum
Open in Discord
Scottish FoldOP
I need to revalidate every 4 minutes (refreshInterval). But I don't want refreshWhenHidden. I would like the SWR to only revalidate when the user is/has focused and the last fetch time is equal to or greater than 4 minutes.

If I just use refreshInterval with revalidateOnFocus=true, it revalidates even though 4 minutes have not passed yet.
If revalidateOnFocus=false, it does not automatically revalidate when the user focuses on the page.

0 Replies