Created
October 7, 2022 15:22
-
-
Save everdimension/fc4eb699d8eb36b8f051ba37bc3532e3 to your computer and use it in GitHub Desktop.
A javascript spinner used to visually help detect freezes in the UI
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 JsSpinner() { | |
const ref = useRef<HTMLDivElement | null>(null); | |
useEffect(() => { | |
let deg = 0; | |
let id = 0; | |
function rotate() { | |
id = requestAnimationFrame(() => { | |
ref.current.style.transform = `rotate(${(deg += 2) % 360}deg)`; | |
rotate(); | |
}); | |
} | |
rotate(); | |
return () => { | |
cancelAnimationFrame(id); | |
}; | |
}, []); | |
return ( | |
<div | |
ref={ref} | |
style={{ height: 20, width: 2, backgroundColor: 'magenta' }} | |
></div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment