Worklets — functions that run on the UI thread.
Basic worklet:
1import Animated, { useSharedValue, useAnimatedStyle } from 'react-native-reanimated';23function AnimatedBox() {4 const offset = useSharedValue(0);56 // Worklet runs on UI thread7 const animatedStyle = useAnimatedStyle(() => {8 'worklet';9 return {10 transform: [{ translateX: offset.value }],11 };12 });1314 return <Animated.View style={[styles.box, animatedStyle]} />;15}
Shared value updates:
1// On JS thread2offset.value = withSpring(100);34// In worklet5'worklet';6const x = interpolate(7 offset.value,8 [0, 1],9 [0, 200]10);
Benefits:
Limitations: