reactjsreact-nativesvg

Got this Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: number


I was running this program to display SVG image

import React, { Component } from 'react';
import { View } from 'react-native';
import Expo from './assets/check-mark.svg';
import SVG from 'react-native-svg';

export default class MyApp extends Component {
 render(){
  return (
    <View style={{backgroundColor:"black"}}>
    <Expo width={20}
    height={15} />
    </View>
   );
 }
}

and came across this error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: number.

How can I resolve this? or is there any other better approach to use SVG image is React Native?


Solution

  • The best way to display an SVG in react-native(according to me, this is the best and easy method) is:

    First install this SVG package: npm i react-native-svg

    Secondly,

    PS: No need to install the SVG transformer package