#ThreeJs Mesh ref not update useEffect

3 messages · Page 1 of 1 (latest)

vagrant urchin
#

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?
@real breach like mentioned

sick oceanBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vagrant urchin
#

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

GitHub

Do you want to request a feature or report a bug? Bug What is the current behavior? It seems useEffect(effect, [ref.current]) is re-running under certain circumstances without the current ref ident...