Created
November 14, 2018 01:25
-
-
Save swyxio/5fd087c2c35398e6f5b328852f24a0bc to your computer and use it in GitHub Desktop.
Timer component for use as a Suspense fallback
This file contains 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
function Timer() { | |
const startTime = React.useRef(performance.now()); | |
const [time, setTime] = React.useState(performance.now()); | |
React.useEffect(() => { | |
const id = setTimeout(() => { | |
ReactDOM.flushSync(() => { | |
setTime(performance.now()); | |
}); | |
}, 2); | |
return () => clearTimeout(id); | |
}); | |
return ( | |
<div className="Fallback"> | |
<h3>🌀 App Level Suspense</h3> | |
<b>{Math.round(time - startTime.current)} ms</b> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: https://twitter.com/swyx/status/1062515316993867777