I found 2 sources where it kind of says that React is using requestAnimationFrame
On this blog post about Om, a ClojureScript framework on top of React. Also on the comments of this SO answer.
I'm not sure it's part of React or if people are using it with React.
Can someone tell me what how requestAnimationFrame
is used in React if it is? Or how it can be used with React and why I would choose to use it with React?
The requestAnimationFrame method returns an integer ID which can be used to cancel the queued request using the cancelAnimationFrame(id) method. The animation callback function can also accept a timestamp value, which is the time elapsed in milliseconds since the web page was loaded.
requestAnimationFrame() method tells the browser that you wish to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint. The method takes a callback as an argument to be invoked before the repaint.
As now you know that the rAF is a Web API, that means the callback will be called asynchronously. Unlike setInterval , requestAnimationFrame does not accept delay argument, instead, it only calls the callback function when the browser is ready to perform the next paint operation.
React Spring is a modern animation library that is based on spring physics. It's highly flexible and covers most animations needed for a user interface.
React doesn't currently use requestAnimationFrame
to do DOM updates (as we call it, the "batching strategy"). The batching strategy is injectible though so it's possible to use something else. Om makes use of that possibility and uses requestAnimationFrame
to batch DOM updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With