元素类型在react native中无效



在My React Native App.js中,我有以下代码

import { StatusBar } from 'expo-status-bar';
import React, { useRef, Component } from 'react';
import { StyleSheet, Text, View, Canvas } from 'react-native';
import { RNCamera } from "react-native-camera";
import * as tf from '@tensorflow/tfjs';
import * as handpose from '@tensorflow-models/handpose';
export default function App() {
const webcamRef = useRef(null);
const canvasRef = useRef(null);
return (
<View style={styles.container}>
<RNCamera ref={webcamRef}
style={{
position: 'absolute',
marginLeft: 'auto',
marginRight: 'auto',
left: 0,
right: 0,
textAlign: 'center',
zIndex: 9,
height: 480,
width: 640
}}
/>
<Canvas ref={canvasRef}
style={{
position: 'absolute',
marginLeft: 'auto',
marginRight: 'auto',
left: 0,
right: 0,
textAlign: 'center',
zIndex: 9,
height: 480,
width: 640
}}
/>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});

上面的代码说:

元素类型无效:期望是字符串(对于内置组件)或类/函数(对于组合组件),但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入

我不认为react-native中有Canvas组件。您正在尝试导入实际react-native框架中不存在的东西。

remove importCanvasfromreact-native.

要实现canvas,你可以使用这个插件代替https://www.npmjs.com/package/react-native-canvas

最新更新