Created
August 18, 2020 15:47
-
-
Save yue4u/447c595ed557a5d38b65aab213cebbe7 to your computer and use it in GitHub Desktop.
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
const ref = useRef() | |
const items = useStore((state) => state.items) | |
const [fast, set] = useState(true) | |
const Component = fast ? ItemFast : ItemSlow | |
// Kick off a render-loop which mutates all state objects/each frame | |
useEffect(() => { | |
let lastCalledTime = Date.now() | |
let fps = 0 | |
function renderLoop() { | |
let delta = (Date.now() - lastCalledTime) / 1000 | |
lastCalledTime = Date.now() | |
fps = 1 / delta | |
ref.current.innerText = 'fps ' + fps.toFixed() | |
useStore.getState().advance() | |
requestAnimationFrame(renderLoop) | |
} | |
renderLoop() | |
}, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment