Replies: 2 comments 3 replies
-
I think this is one of those old 'crossing react roots' issue, so if we encapsulate the components inside a |
Beta Was this translation helpful? Give feedback.
-
this happens because r3f is in a separate react root which runs in a useLayoutEffect calling "render" which react executes async. by the time useEffect fires r3f lags a frame behind, or more, depending on concurrent mode and/or suspense. i don't think there's a solution ... or a problem ... because you should not lift the camera up, but rather distribute the raw state that's controlling the camera down. that's reacts guiding principle: one way data flow as opposed to two way data flow which is always troublesome. in other words, your state model/manager maintains something like if you must access the camera then your code isn't wrong. eventually the ref will be filled, just not in useEffect. so either just leave it like it is and your buttons do: const [cam, set] = useState()
useEffect(() => {
if (cam) { ... }
}, [cam])
return (
<Canvas>
<PerspectiveCamera ref={set}> |
Beta Was this translation helpful? Give feedback.
-
three
version: 0.130.1@react-three/fiber
version: 7.0.5@react-three/drei
version: 7.2.1Problem description:
The custom camera ref is not being set. I need that ref in some custom dom components outside Canvas tree
Relevant code:
See console https://codesandbox.io/s/eager-elgamal-fj401. Is there something I am doing wrong.
Beta Was this translation helpful? Give feedback.
All reactions