You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(This may be a duplicate of unresolved issue here: #724 but I'm not trying to use lazy/suspense as with the issue there).
I'm trying to get svgr SVGs importing dynamically with import(). It kind of works in that you can get the SVG as a component like this, but I'm unable to add props to the imported SVG (as I can with a standard import at the top of the JSX file):
constImportedSvg=({ code })=>{const[SvgComponent,setSvgComponent]=useState(null);useEffect(()=>{import(`ImageImports/${code}.svg`).then(imported=>{// Webpack "sees" this path and uses svgr loader.setSvgComponent(imported.default);});// Or do something similar with async/await.},[code]);// I get an error if I try to return the <Instantiated /> component here, so need to return component definition as imported.returnSvgComponent ? SvgComponent : <LoadingSpinner/>};// This works, but I cannot add props like 'height' to the SVG component, // as I can if i use 'import SvgComponent from "my/svgs/file.svg";'<ImportedSvgcode={code}/>
The text was updated successfully, but these errors were encountered:
tdriley
changed the title
Using props on dynamically-imported svgr SVG componentsn b
Using props on webpack dynamically-imported svgr SVG components
Feb 19, 2024
tdriley
changed the title
Using props on webpack dynamically-imported svgr SVG components
Using props on SVGR components dynamically-imported with webpack
Feb 19, 2024
💬 Questions and Help
(This may be a duplicate of unresolved issue here: #724 but I'm not trying to use lazy/suspense as with the issue there).
I'm trying to get svgr SVGs importing dynamically with
import()
. It kind of works in that you can get the SVG as a component like this, but I'm unable to add props to the imported SVG (as I can with a standard import at the top of the JSX file):The text was updated successfully, but these errors were encountered: