SupremeTechnopriest / react-idle-timer

User activity timer component
https://idletimer.dev
MIT License
1.15k stars 143 forks source link

⚡️ lastActiveTab state: a state to know whether this is the last active tab or not #384

Open aman-godara-ria opened 10 months ago

aman-godara-ria commented 10 months ago

What problem does your feature request solve?

Currently, there is a function that can tell whether a tab is the last active tab or not whenever it is called. I want a state version of it so that components re-render automatically whenever lastActiveTab state changes.

Describe the solution you are proposing.

const { lastActiveTab, isLastActiveTab } = useIdleTimer(....);
// lastActiveTab is either true or false
// isLastActiveTab is a fn which returns true, false or null

Describe alternatives you have considered.

none

Importance

I Need It

Additional Context

aman-godara-ria commented 10 months ago

nevermind, I was able to create a custom hook on top of useIdleTimer using onAction & onMessage props with crossTab: true

useIdleTimer({ crossTab: true, onAction: (_, api) => { api.message() }, onMessage: ... })

Not closing this feature request, just in case if react-idle-timer's team wants to provide this feature out-of-the-box. Thanks a lot for the library btw, I really liked some of the optimization features of the library to reduce computation.