I have a component that accepts: itemName and spills out an html package containing an image. The image for each beam is different.
Here is 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 can I make this component work?
I know that if I just imported all my images explicitly, I could just call my images like this ...
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 will work, but since I need to enable ~ 60 svgs, it will add a lot of redundant code.
Also, I found this code in this question ...
import * as IconID from './icons';
But this does not work (it was a question, not an answer), and the answer was too nonspecific to answer the question I ask.
I also found this question , but again there is an answer (although not approved) that has more questions than answers. So, after setting the reaction-svg, I set up a test to see if the answer works like that ...
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, as the OP asked this question, the page cannot find my SVG even after copying the entire image folder to my build folder. I also tried "./images/"
It seems to me that I just missed the last key piece of information, and after I looked for the last day, I hoped that someone would be able to determine which part I was missing.