How to combine worklets and useImperativeHandle? #5199
Unanswered
enzomanuelmangano
asked this question in
Q&A
Replies: 3 comments 1 reply
-
@enzomanuelmangano Thanks so much for posting this. I thought I was going crazy—I'm experiencing the same issue with an Imperative Handle and the same error. I kept trying to fix it the wrong way, but now I know what the problem is. It looks like I'll need to find a different method to get it to work without the Imperative Handle for now. Cheers! |
Beta Was this translation helpful? Give feedback.
0 replies
-
same here |
Beta Was this translation helpful? Give feedback.
0 replies
-
@enzomanuelmangano @mr-ryan-james did you guys find any workaround? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Specifically, the problem I am experiencing occurs when I try to pass a function into useImperativeHandle, for instance:
scrollTo is a worklet, but when I pass it into the ref and try to call it from the parent component, I can't reuse it as a worklet.
For example, the code below will not work and we'll get the error "Cannot assign to read-only property 'current'".
What is interesting is that by doing a hot reload and passing the same code instead, the function will be considered a worklet 🫣
However, I was wondering if there was a way to handle this pattern so that the function of a child component could be reused in a parent component.
An initial idea was to not use the useImperativeHandle but perhaps pass the function into a SharedValue, but unfortunately even then it does not work, since we can't pass functions through SharedValues 🙄
I sincerely hope that someone has an answer to this topic 🥹
Beta Was this translation helpful? Give feedback.
All reactions