Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does React use requestAnimationFrame? If so, how does it use it?

Tags:

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?

like image 758
Sebastien Lorber Avatar asked Jan 25 '14 15:01

Sebastien Lorber


People also ask

How does react use requestAnimationFrame?

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.

What is requestAnimationFrame used for?

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.

Is requestAnimationFrame asynchronous?

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.

Which react tool is used for animation?

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.


1 Answers

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.

like image 187
Paul O'Shannessy Avatar answered Oct 01 '22 10:10

Paul O'Shannessy