简体   繁体   中英

Using SVG files as a React Component in a CRA app

I'm trying to import an svg file but as a react component but I can't see the actual icon. I expect to see a Home Icon but all I'm seeing is a black-filled figure.

What I tried

import {ReactComponent as Home} from '../assets/svgs/home.svg'; 
import {List, ListItem, ListItemIcon} from '@material-ui/core'; 

<List>
 {['Home', 'Video', 'Music', 'Sound', 'Painting', 'Images', 'Heritage', 'Fashion'].map((text, index) => (
          <ListItem button key={text}>
            <ListItemIcon>{index % 2 === 0 ? <Home/> : <MailIcon />}</ListItemIcon>
            <ListItemText primary={text} />
          </ListItem>
      ))}
<List/>

My SVG File

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
  viewBox="0 0 512.000000 512.000000"
 preserveAspectRatio="xMidYMid meet" width="25px" height="25px">

<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M0 2560 l0 -2560 2560 0 2560 0 0 2560 0 2560 -2560 0 -2560 0 0
-2560z"/>
</g>
</svg>

What I'm getting

在此处输入图片说明

What am I doing wrong? I'd really appreciate your help.

I just checked your SVG on this site: http://svg.enshrined.co.uk/

The SVG itself is broken I suggest you find another.

Your SVG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM