pmndrs / use-cannon

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

Documentation example - useBox not working. #89

Closed tiagotedsky closed 4 years ago

tiagotedsky commented 4 years ago

Hello, I was trying to run the box example on my machine, but I am getting the following error

TypeError
Cannot read property 'map' of undefined
eval
https://l40oh.csb.app/node_modules/use-cannon/dist/index-c37b3110.js:235:14
x
https://l40oh.csb.app/node_modules/use-cannon/dist/index-c37b3110.js:78:19
eval
https://l40oh.csb.app/node_modules/use-cannon/dist/index-c37b3110.js:109:16
commitHookEffectListMount
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:11025:26
commitLifeCycles
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:11081:9
commitLayoutEffects
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:14234:7
HTMLUnknownElement.callCallback
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:10652:14
Object.invokeGuardedCallbackDev
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:10701:16
invokeGuardedCallback
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:10753:31
commitRootImpl
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:13972:9
unstable_runWithPriority
https://l40oh.csb.app/node_modules/react-reconciler/node_modules/scheduler/cjs/scheduler.development.js:653:12
runWithPriority
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:1761:10
commitRoot
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:13812:3
finishSyncRender
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:13210:3
performSyncWorkOnRoot
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:13196:7
eval
https://l40oh.csb.app/node_modules/react-reconciler/cjs/react-reconciler.development.js:1811:24
unstable_runWithPriority

It is fixed by adding args

  const [ref, api] = useBox(() => ({
    mass: 1,
    args: [1, 1, 1], <---- 
    position: [0, 5, 0],
    rotation: [0.4, 0.2, 0.5],
    ...props,
  }));

You can try it on codesanbox ( https://codesandbox.io/s/r3f-cannon-instanced-physics-l40oh ) Just update the version.

I am a noob on open source, I can pair with anyone to fix this, otherwise it's ok.

Thank you for amazing work.

codynova commented 4 years ago

Hi @TiagoEsterisco, thanks for the detailed bug report. This bug was accidentally introduced in use-cannon@0.4.7. I've just released use-cannon@0.4.9 which includes a fix. Make sure you refresh the codesandbox browser window after updating the dependency :)

tiagotedsky commented 4 years ago

Thanks @codynova!