brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
812 stars 102 forks source link

Strongly typed ref in BabylonNode<T> #218

Closed coder89 closed 2 years ago

coder89 commented 2 years ago

Currently BabylonNode<T> declares ref as Ref<ReactNode>. Therefore we need to write something like this:

const ref = useRef();
useEffect(() => {
  const mesh = ref.current as Mesh;
}, []);
return <mesh ref={ref} />

generatedProps.d.ts should be updated to allow below:

const ref = useRef<Mesh>();
useEffect(() => {
  const mesh = ref.current;
}, []);
return <mesh ref={ref} />

I have created a PR that fixes the issue: #217

brianzinn commented 2 years ago

Thanks. I’ll merge in tonight. Appreciate the PR!