最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Warning: React.jsx: type is invalid -- expected a string when adding an image as a component - Stack Overflow

programmeradmin1浏览0评论

Trying to create a body structure on my React Native app using images as buttons.

I get hit with an error "Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: number." at this particular segment.

PointsHistory.tsx:

import Buttonicon from "../assets/buttonicon.svg";

<Buttonicon
  style={[styles.buttonicon, styles.icon25Layout]}
  width={24}
  height={24}
>

What am I doing wrong here?

Trying to create a body structure on my React Native app using images as buttons.

I get hit with an error "Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: number." at this particular segment.

PointsHistory.tsx:

import Buttonicon from "../assets/buttonicon.svg";

<Buttonicon
  style={[styles.buttonicon, styles.icon25Layout]}
  width={24}
  height={24}
>

What am I doing wrong here?

Share Improve this question asked Mar 6 at 7:31 Udhayan NairUdhayan Nair 4702 gold badges8 silver badges25 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use image component for svg image display , but it will only work for iOS .

    import { Image } from 'react-native';

  const App = () => {
  return (
    <Image source={require('./assets/image.svg')} style={{ width: 100, height: 100 }} />
  );
};

If you want to support both platform react-native-svg is the best choice

发布评论

评论列表(0)

  1. 暂无评论