From de98f6ace31a629c96139fef992ac804ff634aaa Mon Sep 17 00:00:00 2001 From: Leroy Korterink Date: Mon, 15 May 2023 18:35:32 +0200 Subject: [PATCH] Add delta time to test implementation in storybook --- .../useAnimationLoop/useAnimationLoop.stories.tsx | 13 ++++++++++--- src/hooks/useAnimationLoop/useAnimationLoop.ts | 15 +++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/hooks/useAnimationLoop/useAnimationLoop.stories.tsx b/src/hooks/useAnimationLoop/useAnimationLoop.stories.tsx index 1378881..06a2770 100644 --- a/src/hooks/useAnimationLoop/useAnimationLoop.stories.tsx +++ b/src/hooks/useAnimationLoop/useAnimationLoop.stories.tsx @@ -9,10 +9,16 @@ export default { }; function DemoComponent(): ReactElement { - const [currentTimestamp, setCurrentTimestamp] = useState(Date.now); + const [delta, setDelta] = useState(0); + const [currentTimestamp, setCurrentTimestamp] = useState(0); + const [isRunning, toggleIsRunning] = useToggle(true); + useAnimationLoop(() => { - setCurrentTimestamp(Date.now); + const timestamp = Date.now(); + + setDelta(timestamp - currentTimestamp); + setCurrentTimestamp(timestamp); }, isRunning); return ( @@ -24,7 +30,8 @@ function DemoComponent(): ReactElement {
Test Area
-

{currentTimestamp}

+

Current time: {currentTimestamp}

+

Delta: {delta}