Best practices to save performance, pause rendering when nothing happens? #1701
-
Hi everyone, I'm wondering what the best practices are to save performance when using r3f? For example, can I pause the rendering of my canvas when nothing happens on the screen, like when an animation depends on scrolling? Greetings |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You can render on demand by setting Here are some guides on best practices and how to combine them with the new regress API:
As for pausing when the canvas isn't in view, you can use the observer API to know when the canvas is on screen: We do this on the website to handle loading states (see component) but you can unmount the canvas or change the frameloop in the same way. |
Beta Was this translation helpful? Give feedback.
You can render on demand by setting
frameloop="demand"
. This will callinvalidate
to request a new frame when the scene graph has changed. Libraries like Drei and react-spring will call this for you.Here are some guides on best practices and how to combine them with the new regress API:
As for pausing when the canvas isn't in view, you can use the observer API to know when the canvas is on screen:
We do this on the website to handle loading states (see component) but you can unmount the …