pmndrs / use-cannon

👋💣 physics based hooks for @react-three/fiber
https://cannon.pmnd.rs
2.74k stars 154 forks source link

use forwardRef without casting #273

Closed bjornstar closed 2 years ago

bjornstar commented 2 years ago

This is a backwards compatible change that enables the use of forwardRef without casting.

Currently we have to use forwardRef like this:

const Ball = forwardRef<Object3D, SphereProps>((props, ref) => {
  const [, { position }] = useSphere(
    () => ({ type: 'Kinematic', args: 0.5, ...props }),
    ref as RefObject<Object3D>,
  )
}

With this change we can use ref directly:

const Ball = forwardRef<Object3D, SphereProps>((props, ref) => {
  const [, { position }] = useSphere(() => ({ type: 'Kinematic', args: 0.5, ...props }), ref)
}