-
-
Save madiodio/1832fc6e76096f19142c5c90cfc2cab0 to your computer and use it in GitHub Desktop.
Control the speed at which your loading state shows up depending on the user's internet speed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultDelay = 500; | |
export default function getDelay(): number { | |
if (typeof window !== "undefined") { | |
if (window.navigator && window.navigator.connection) { | |
const connection = window.navigator.connection.effectiveType; | |
switch (connection) { | |
case "4g": | |
return defaultDelay; | |
case "3g": | |
return 200; | |
case "2g": | |
return 0; | |
default: | |
return defaultDelay; | |
} | |
} | |
} | |
return defaultDelay; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment