This is my babel file
My code:
import React, { useRef, useState } from 'react'
import { View, useWindowDimensions, Button } from 'react-native'
import Animated, { runOnUI } from 'react-native-reanimated';
export default function Login() {
const { width, height } = useWindowDimensions();
// const value = useSharedValue(0);
function someWorklet(greeting: any) {
'worklet';
console.log("Hey I'm running on the UI thread");
}
return (
<View style={{ flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
<Button title="click me" onPress={() => runOnUI(someWorklet)('Howdy')} />
</View>
);
}
The package I installed is "react-native-reanimated": "^2.1.0"
I followed their installation process: React Native Reanimated instalation guide.
The error is:
Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated's babel plugin?
I have found this issue on this link. These are the steps that I have followed for having my project up and running without any errors:
yarn add react-native-reanimated@next react-native-gesture-handler
import 'react-native-gesture-handler'
to App.tsx file at the top of the file before importing any packagesbabel.config.js
file and add react-native-reanimated/plugin
to pluginsmodule.exports = {
presets: ["module:metro-react-native-babel-preset"],
plugins: [
"react-native-reanimated/plugin",
],
};
yarn start --reset-cache
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With