How to Use Loaded SVG Module

隐身守侯 提交于 2021-01-29 08:11:16

问题


I have set up webpack to load SVG files into my TSX port of the create-react-app, per this answer:

const logo = require('./logo.svg');

However, when I try to use it as follows I get a nasty 404.

<img src={logo} className="App-logo" alt="logo" />
Failed to load resource: the server responded with a status of 404 ()        [object%20Module]:1 

This makes sense - I require the svg, so it loads as a module, and you can't jolly well make a src URL out of that.

That being said, how do I use an SVG loaded into a TSX file as a module via require? Is this possible? I am aware the above answer is outvoted by the more popular approach specified here, but I want to see if this option can work as well. Because what is programming if not a thousand ways to skin a cat? Or shoot yourself in the foot...

来源:https://stackoverflow.com/questions/65205211/how-to-use-loaded-svg-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!