Skip to main content
Version: 1.0 (beta)

Installation

Check the compatibility table to find the Worklets version that supports your React Native version.

Worklets 1.0 needs Metro 0.88.0 or newer and React Native 0.89 or newer, which together support inline modules.

Step 1: Install the package​

Install react-native-worklets package from npm:

npm install react-native-worklets

Step 2: Configure your project​

The remaining steps depend on how you build your app — pick your framework:

Run prebuild to update the native code in the ios and android directories.

npx expo prebuild

And that's it! The Worklets library is now configured in your Expo project.

Don't I need the Worklet Syntax Babel plugin?

Since Expo SDK 54, the Expo starter template includes the Worklet Syntax Babel plugin by default, so there's nothing to add. On older SDKs, add react-native-worklets/plugin to your babel.config.js as described in the React Native Community CLI tab.

To learn more about the plugin go to Worklet Syntax plugin section.


Configure Metro​

Worklets run in Bundle Mode, which needs a Metro configuration. Follow the Metro steps of the Bundle Mode setup before you start the app.

npx expo start --clear

Step 3: Patch metro-runtime for Fast Refresh​

Temporary

Fast Refresh on Worklet Runtimes uses HMRClient.addModuleUpdateListener from metro-runtime. This API is proposed in react/metro#2312 and no Metro release has it yet. Until one does, apply the patch below to metro-runtime 0.88, for example with yarn patch metro-runtime or patch-package. It adds the API to src/modules/HMRClient.js. Without the patch, a worklet function that Fast Refresh changes fails on Worklet Runtimes until you reload the app.

diff --git a/src/modules/HMRClient.js b/src/modules/HMRClient.js
--- a/src/modules/HMRClient.js
+++ b/src/modules/HMRClient.js
@@ -2,7 +2,18 @@

const EventEmitter = require("./vendor/eventemitter3");
const HEARTBEAT_INTERVAL_MS = 20_000;
+const moduleUpdateListeners = new Set();
const inject = ({ module: [id, code], sourceURL }) => {
+ Array.from(moduleUpdateListeners).forEach(({ listener }) => {
+ try {
+ listener(code, sourceURL);
+ } catch (error) {
+ console.error(
+ `Error while calling a module update listener for module ${id}: `,
+ error,
+ );
+ }
+ });
if (global.globalEvalWithSourceUrl) {
global.globalEvalWithSourceUrl(code, sourceURL);
} else {
@@ -14,6 +25,15 @@
update.modified.forEach(inject);
};
class HMRClient extends EventEmitter {
+ static addModuleUpdateListener(listener) {
+ const entry = { listener };
+ moduleUpdateListeners.add(entry);
+ return {
+ remove: () => {
+ moduleUpdateListeners.delete(entry);
+ },
+ };
+ }
_isEnabled = false;
_pendingUpdate = null;
_queue = [];