Skip to content

Best way to use html over the r3f canvas #1536

Answered by drcmda
Josehower asked this question in Q&A
Discussion options

You must be logged in to vote

i would not use a raf, r3f already has one that you can re-use, having two hurts performance. there is an addEffect export

useEffect(() => addEffect(() => ...), [])

this can be used outside of r3f and it will auto-cleanup.

other than that you can do something like this: https://github.com/pmndrs/racing-game/blob/414ff101d6c9d8682f219a7f2bfb615153670349/src/ui/Speed.jsx#L4-L27 look into that game in general for hints.

the most important thing is that you do not setstate fast updates. updating your bar 60 times a sec in a loop via setstate, you don't even need to continue working on the game after that because you have stolen 95% of the cpu's capacity. in the example above i mutate the html…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Josehower
Comment options

@Josehower
Comment options

@drcmda
Comment options

@Josehower
Comment options

Answer selected by Josehower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants