Can I use ref and useFrame to handle my states more optimally than using useState?


I have a mesh that can have states that vary more or less quickly, sometimes it changes once a second, others a hundred times a second.
I use a useState to manage the states, but it sometimes leads to framerate drops.
So I was wondering if using ref on the mesh and with useFrame could have better performance for state management.
Which makes me ask directly another question. If the state doesn’t change for a second or more, does the mesh still render every frame? If so, how to avoid unnecessary rendering?

Mostly everything except flag state goes into useFrame which also allows you to animate state changes. These drops most likely have another reason, some things in three you cannot add runtime, materials etc. It sounds to me like you’re creating something from scratch each render or sth like that. A setState alone won’t cause a skip.

1 Like

Ok, I’m effectively recreating from scratch some things, thank you!
And about the second question? Will useFrame do useless computations for frames with no change in the mesh attributes?