【发布时间】:2021-02-26 06:43:52
【问题描述】:
我想在我的 React 本机应用程序中使用 svg 文件,为此我遵循 react-native-svg 包的文档并尝试实现手动链接方式来使用 svg 图像。但我得到错误:元素类型无效:期望字符串(用于内置组件)或类/函数(用于复合组件)但得到:数字。请提出解决方案。
代码
import React from 'react';
import UserImg from './assets/vcraft_logo.svg';
import {StyleSheet, View, Text, StatusBar} from 'react-native';
const App = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<View style={styles.container}>
<Text>Icon</Text>
<UserImg width={120} height={40} />
</View>
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default App;
【问题讨论】:
标签: reactjs react-native react-native-svg