kevinabouhanna / abouhanna

Kevin's Personal Website
https://www.abouhanna.com
MIT License
2 stars 1 forks source link

R&D - Technical Debt: use setTimeout proper alternative #13

Open kevinabouhanna opened 2 years ago

kevinabouhanna commented 2 years ago

https://usefulangle.com/post/280/settimeout-setinterval-on-inactive-tab https://www.w3.org/TR/page-visibility/

Thank you for the feedback @hassan-jammal

karamgaby commented 2 years ago

check about using this event listener document.addEventListener('visibilitychange',function(){} );

An example of how I have implemented this feature can be found here https://github.com/gk-git/gabykaram/blob/main/src/components/Global/CurrentlyPlaying/CurrentlyPlaying.tsx.

But I took a simple decision to not run the API call when the tab isn't active