ref to mesh is always undefined or null #3166
-
Hi all, I am currently creating an application that uses react three that loads a model and animates it on scroll, using GSAP. I already tried to wrap the
with a separate mesh and assigning the ref to that, but alway null or undefined. What am I doing wrong? thanks! full code for container
and the SplineElement `
` |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
update: I added this to the mesh componentn type Props = { useEffect(() => { Making it so, that it called a function on the parent, so that I can do a state update, triggering the useEffect again. That seemed to work. |
Beta Was this translation helpful? Give feedback.
update:
I added this to the mesh componentn
type Props = {
rotation: [number, number, number];
ref: Ref<Group>;
onLoad: () => void;
};
export const SplineElement = forwardRef((props: Props, ref) => {
const { rotation, onLoad } = props;
const { nodes, materials } = useGLTF("/glbs/Smartphone.glb");
useEffect(() => {
onLoad();
}, [onLoad]);
Making it so, that it called a function on the parent, so that I can do a state update, triggering the useEffect again. That seemed to work.