Skip to content

User inactivity #862

Answered by joaobibiano
joaobibiano asked this question in Q&A
Jan 5, 2021 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

For those who need implent this, I would like to suggest a temporary solution like this

 const userIsInactive = useIdle(TIME_TO_CONSIDER_USER_INACTIVE);

 const { data: tabCounters } = useSWR(
  userIsInactive ? null : "request-key",
  fetcher,
  {
    refreshInterval: TIME_TO_FETCH_COUNTERS
  }
);

You can find the hook useIdle here https://github.com/streamich/react-use/blob/master/docs/useIdle.md

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@joaobibiano
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by joaobibiano
Comment options

You must be logged in to vote
2 replies
@joaobibiano
Comment options

@huozhi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants