3 ms·
The TypeScript example does feel a little weird. I've used this library successfully with React + TypeScript with the following pattern: const mesh = useRef<
by sswu 5y ago
The TypeScript example does feel a little weird. I've used this library successfully with React + TypeScript with the following pattern:
const mesh = useRef<THREE.Mesh>(null); // mesh has type RefObject<THREE.Mesh | null>
...
useFrame((): void => {
if (mesh.current != null) {
mesh.current.rotation.x += 0.01;
}
});
...
return <mesh ref={mesh} ... />
As others have mentioned, the ref will typically attach by the time a `useEffect` hook is called, but for safety it's nice to have the null check.