AllienWorks / cryptocoins

Cryptocoins is the most complete vector/webfont icon pack of your favourite cryptocurrencies
https://allienworks.github.io/cryptocoins/icons-demo
MIT License
828 stars 195 forks source link

Using SVG URL in React rendering #44

Closed juanparadox closed 7 years ago

juanparadox commented 7 years ago

Is there an easier way to be able to use these SVG files in React since relative URL strings do not work great when rendering a React component?

Importing ALL of the SVG files one by one seems like overkill and there may be cases where not all are needed.

AllienWorks commented 7 years ago

Hey, I'm sorry but I don't have any experience with React, so I won't be able to solve your issue. However I'll leave it here so somebody else can help you out.

If you find a solution to your problem, please post it here so even others can benefit from it.

kazazor commented 7 years ago

You can just use webpack and require for that:

{
        test: /\.svg$/,
        use: [
          {
            loader: 'file-loader'
          }
        ]
      },
const svg = require(`cryptocoins-icons/SVG/${dynamicCoinCode.toUpperCase()}.svg`);
const altSvg = require(`cryptocoins-icons/SVG/${dynamicCoinCode.toUpperCase()}-alt.svg`);