admin管理员组文章数量:1277607
I'm learning React Native Reanimated version 2, but I got an issue when creating a function that calls 'worklet'
.
I installed React Native Reanimated version 2 on a React Native bare project that was created with npx react-native init myApp
.
I have followed all the installation instructions, as follows.
- Configuring the
babel.config.js
:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'react-native-reanimated/plugin'
]
};
- Enabling Hermes, setting it to true.
- Configuring the
MainApplication.java
file. - Cleaning the build.
- Resetting the cache using
yarn start --reset-cache
.
I try to make a simple Worklet function like this:
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;
As you can see, the code in App.js
is simple, but when I call 'worklet'
, I always get an undefined is not a function
error as shown below.
I'm learning React Native Reanimated version 2, but I got an issue when creating a function that calls 'worklet'
.
I installed React Native Reanimated version 2 on a React Native bare project that was created with npx react-native init myApp
.
I have followed all the installation instructions, as follows.
- Configuring the
babel.config.js
:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'react-native-reanimated/plugin'
]
};
- Enabling Hermes, setting it to true.
- Configuring the
MainApplication.java
file. - Cleaning the build.
- Resetting the cache using
yarn start --reset-cache
.
I try to make a simple Worklet function like this:
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;
As you can see, the code in App.js
is simple, but when I call 'worklet'
, I always get an undefined is not a function
error as shown below.
1 Answer
Reset to default 12Ohh i feel like a stupid man...
I just need to import the react-native-reanimated
in the App.js
and all done.. :)
import 'react-native-reanimated'
It looks like the react-native-reanimated v2 documentation doesnt mention to import the react-native-reanimated
on to the top of our project...
版权声明:本文标题:javascript - Cannot define a function calling 'worklet': "undefined is not a function" - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741203513a2357694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论