Organising constraints #141
-
I've made a small demo of a constraint - https://codesandbox.io/s/usecannon-constraints-nvc5o - but I'm wondering if there's a better way to organise the code. I can't pass a ref to the Ball as it's a function, and I don't appear to be able to use a forwardRef either, so do I have to define all my physics hooks and constraints in a parent the way I have in my demo, or is there something I've missed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It's possible to use forwardRef (see below, I moved Maybe if you set up a custom ref callback you can solve the timing in a more reliable way. But ultimately this seems like an issue with use-cannon. |
Beta Was this translation helpful? Give feedback.
It's possible to use forwardRef (see below, I moved
useSphere
intoball.js
), but there seems to be some timing bug where it sets up the constraint before the ref is set. I've added a small timeout before setting up the constraint, which works but I wouldn't trust:https://codesandbox.io/s/usecannon-constraints-forked-qp0dg
Maybe if you set up a custom ref callback you can solve the timing in a more reliable way. But ultimately this seems like an issue with use-cannon.