Next.js Discord

Discord Forum

ThreeJs Mesh ref not update useEffect

Answered
B33fb0n3 posted this in #help-forum
Open in Discord
Hey, I have a ref and this ref willl be used to update the cam position (.fitToBox): https://paste.gg/p/B33fb0n3/af6e29a68e6d4c7cb9db2e4ef9554997
(the other case with .setLookAt works fine and is not important in this case)

Initially the meshRef is null, but then should update when the mesh is mounted. But it does not update the useEffect.

I tried these three variants: https://paste.gg/p/B33fb0n3/12f2710a75e94c728f8e37fb3947921e
But even if the mesh is then set, it won't trigger "exists x". I also tried useLayoutEffect

How will the useEffect be triggered, when the meshRef exists?
@@ts-ignore like mentioned
Answered by B33fb0n3
Fixed by using the mentioned code:
https://github.com/facebook/react/issues/14387#issuecomment-493677168

Now the code looks like this and does what it should do:
https://paste.gg/p/B33fb0n3/87dbd9d68b084a908213e4762643569f
View full answer

1 Reply

Fixed by using the mentioned code:
https://github.com/facebook/react/issues/14387#issuecomment-493677168

Now the code looks like this and does what it should do:
https://paste.gg/p/B33fb0n3/87dbd9d68b084a908213e4762643569f
Answer