![](/img/trans.png)
[英]Cannot find module 'react-native-reanimated/plugin' from /projectFolder
[英]react-native-reanimated 2: cannot make a function with 'worklet' keyword (undefined is not a function)
我只是在学习react-native-reanimated
v2,但是在使用“worklet”关键字创建函数时遇到了问题。
我使用npx react-native init myApp
在 React Native裸项目上安装了react-native-reanimated
v2。
我遵循了所有react-native-reanimated
v2 安装说明,包括:
module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ 'react-native-reanimated/plugin' ] };
MainApplication.java
文件yarn start --reset-cache
重置yarn start --reset-cache
我尝试制作一个简单的“worklet”函数,如下所示:
import React from 'react'; import { View, Button } from 'react-native'; const App = () => { const someWorklet = () => { 'worklet'; console.log('this run on UI thread'); }; return ( <View > <Button title="Press" onPress={() => { }} /> </View> ); }; export default App;
正如你在上面看到的,它只是App.js
上的一个简单代码,但如果我把'worklet'
关键字,它总是undefined is not a function
错误:
呵呵,感觉自己是个傻子……
我只需要在App.js
导入react-native-reanimated
App.js
可以了。:)
import 'react-native-reanimated'
看起来 react-native-reanimated v2 文档没有提到将react-native-reanimated
导入到我们项目的顶部...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.