【问题标题】:ERROR Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: numberERROR 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:数字
【发布时间】: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


    【解决方案1】:

    使用&lt;img src={UserImg} /&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      • 2021-01-18
      • 1970-01-01
      • 2022-06-11
      • 2020-11-06
      • 2020-03-07
      相关资源
      最近更新 更多