-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add useAnimationLoop hook #129
base: main
Are you sure you want to change the base?
Conversation
6a83dd7
to
af949e6
Compare
`useAnimationLoop` hook is a wrapper around requestAnimationFrame function. This hook will execute | ||
the passed callback function every frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`useAnimationLoop` hook is a wrapper around requestAnimationFrame function. This hook will execute | |
the passed callback function every frame. | |
`useAnimationLoop` hook is a wrapper around the `requestAnimationFrame` function. This hook will invoke | |
the passed `callback` function every frame. |
- `callback` - function accepts `delta` parameter which represents time passed since last | ||
invocation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `callback` - function accepts `delta` parameter which represents time passed since last | |
invocation; | |
- `callback` - a function that receives a `delta` parameter which represents time passed since last | |
invocation, in milliseconds, as a [DOMHighResTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp) |
const [currentTimestamp, setCurrentTimestamp] = useState(Date.now); | ||
const [isRunning, toggleIsRunning] = useToggle(true); | ||
useAnimationLoop(() => { | ||
setCurrentTimestamp(Date.now); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example, it might be more useful to do something (e.g. log) the delta
that is passed, to better showcase the features of this hook.
* useAnimationLoop hook is a wrapper around requestAnimationFrame method. | ||
* This hook will execute a callback function every next frame. | ||
* | ||
* @param callback - callback function with @param delta which represents time passed since last invocation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docs (still) say delta
, while the implementation (has changed?) returns the actual time.
When running an individual animationFrame, the time might be useful. When you running them in a loop, the delta is often more useful.
I don't mind also forwarding the timestamp, but I feel we should at least calculate and pass the delta.
useAnimationLoop
hook is a wrapper around requestAnimationFrame function.This hook will execute the passed callback function every frame.