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> #217

Closed coder89 closed 2 years ago

coder89 commented 2 years ago

Fixes typescript error for a given case:

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

Without that change one needs to write below code to workaround type check errors which defeats the purpose:

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

thanks Lukasz!! That's a helpful addition 😄