pmndrs / use-cannon

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

Fix return type of subscribe function #252

Closed skuteli closed 3 years ago

skuteli commented 3 years ago

The example in Readme calls for using unsubscribe in useEffect like this: return ()=>unsubscribe() This raises an error as the return type of api.whatever.subscribe(...) is void. In fact proper value is returned, but the example wraps unnecessarily and type definition is void instead of ()=>void. Also fixed Readme because this arrow function is not needed. Could be even

useEffect(() => api.velocity.subscribe((v) => (velocity.current = v)), [])

instead of

useEffect(() => {
  const unsubscribe = api.velocity.subscribe((v) => (velocity.current = v))
  return () => unsubscribe()
}, [])

but I don't have enough courage to change that much ;)

bjornstar commented 3 years ago

Thanks, I wonder if there is a rule in typescript that prevents this type of error.