ThreeJs Mesh ref not update useEffect
Answered
B33fb0n3 posted this in #help-forum
B33fb0n3OP
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
How will the useEffect be triggered, when the meshRef exists?
@@ts-ignore like mentioned
(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
useLayoutEffectHow 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
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
1 Reply
B33fb0n3OP
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
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