Skip to content

When am I supposed to use runOnJS?? #2292

Answered by j-piasecki
chen-rn asked this question in Q&A
Discussion options

You must be logged in to vote

Reanimated's worklets are executed on the UI thread and not the JS one. You can use runOnJS and runOnUI to schedule execution of a function on a different thread than you currently are, i.e. you should use runOnUI on the JS thread when you want some code to execute on the UI thread and similarly, you should use runOnJS on the UI thread when you want some code to execute on the JS thread. Keep in mind that only worklets can be executed on the UI thread, that's why you need to use runOnJS when changing state.

As a sidenote, if you don't want the callbacks of a gesture running on the UI thread, you can use .runOnJS(true) modifier, i.e.:

const pan = Gesture.Pan().runOnJS(true);

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@chen-rn
Comment options

@chen-rn
Comment options

@j-piasecki
Comment options

@chen-rn
Comment options

@vkukade-altir
Comment options

Answer selected by m-bert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants