I have a component that takes in an :itemName and spits out an html bundle containing an image. The image is different for each bundle.
Here's what I have:
import React, { Component } from 'react';
import { NavLink } from 'react-router-dom';
import SVGInline from "react-svg-inline";
export default (props) => (
<NavLink className="hex" activeClassName="active" to={'/hex/' + props.itemName}> {React.createElement(SVGInline, {svg: props.itemName})} </NavLink>
)
How could I make this component work?
I know that if I just imported all my images explicitly, I could just call my images like so...
import SVGInline from "react-svg-inline";
import SASSSVG from "./images/sass.svg";
<NavLink className="hex" activeClassName="active" to="/hex/sass"><SVGInline svg={ SASSSVG } /></NavLink>
This would work, but since I need to include ~60 svgs, it adds A LOT of excess code.
Also, I found in this question this code...
import * as IconID from './icons';
But that doesn't seem to work (it was part of the question, not the answer), and the answer was a bit too nonspecific to answer the question I'm asking.
I also found this question but again there's an answer (although unapproved) that possess more questions than it answers. So, after installing react-svg, I set up a test to see if the answer works like so...
import React, { Component } from 'react';
import ReactDOM from 'react-dom'
import { NavLink } from 'react-router-dom';
import ReactSVG from 'react-svg'
export default (props) => (
<NavLink className="hex" activeClassName="active" to={'/hex/' + props.itemName}>
<ReactSVG
path={"images/" + props.itemName + ".svg"}
callback={svg => console.log(svg)}
className="example"
/>
</NavLink>
)
But, just as the OP of that question was asking, the page can't find my svg even after copying my entire image folder into my build folder. I've also tried "./images/"
I feel like I'm just missing one last key piece of information and after searching for the past day, I was hoping someone could identify the piece I'm missing.