How to combine worklets and useImperativeHandle? #5199
Unanswered
enzomanuelmangano
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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