Worklet

Also called Worklets

Also known as
Worklets
Updated

What is Worklet in React Native?

A worklet is a small JavaScript function marked to run on the UI thread instead of the JavaScript thread, so animations and gestures stay smooth while JS is busy.

A worklet is a JavaScript function that has been marked to run on the UI thread rather than the main JavaScript thread. It is the core idea behind Reanimated.

You mark one with the 'worklet' directive, though in practice the Babel plugin adds it for you inside hooks like useAnimatedStyle:

const style = useAnimatedStyle(() => {
  'worklet';
  return { opacity: progress.value };
});

Because the worklet executes on the UI thread, it can compute a new style every frame even while JavaScript is blocked parsing a large API response. That is why a Reanimated gesture keeps tracking your finger when a setState-driven animation would freeze.

The trade-off is isolation: a worklet runs in a separate context, so it can only use values explicitly captured from the enclosing scope, plus shared values. Calling back into normal JS needs runOnJS. See the Reanimated glossary.