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
import two different SVG images as React components into the index.js
create a component able to accept another React component as a property (in my case, I created a Button component which accepts an icon; icon is meant to be a component).
create two Buttons, each receiving a different SVG image component as icon
import{ReactComponentasSearch}from"./search.svg";import{ReactComponentasCross}from"./cross.svg";importButtonfrom"./Button";import"./styles.css";functionApp(){return(<divclassName="App"><h1>Weird problem with SVG imports</h1><p>
The following buttons should have different icons, <br/>
the first should be a magnifying glass and the second should be a cross.
</p><Buttonicon={Search}>Magnifying glass</Button><Buttonicon={Cross}>Cross</Button><p>Unfortunately, both buttons seem to display a magnifying glass</p></div>);}
Expected Behavior
The two button should render with different images
Actual Behavior
The two button both display the first rendered SVG image
Hey buddy,
The SVG's are very badly made and exported, if you tried any other SVG you would see that it works perfectly.
Why?
Explanation
Simple.
If you open the svg in a editor you will see that their id's and mask url's are identical.
If you still wanna use these, you can get them here, I fixed them for you.
Have fun and good luck with your project!
@Malldoror thank you so much for your detailed explanation and for your help! I am not an SVG expert, didn't make them myself and I assumed they were OK 😊 .
Is this a bug report?
Yes
Did you try recovering your dependencies?
The problem happens in a brand new demo project started with
create-react-app
.Which terms did you search for in User Guide?
SVG, svg import
Environment
Pasting the result of
npx create-react-app --info
but my test case is on CodeSandbox anyway:Steps to Reproduce
TLDR: CodeSandbox: https://codesandbox.io/s/o45v70nv15
index.js
icon
;icon
is meant to be a component).icon
Expected Behavior
The two button should render with different images
Actual Behavior
The two button both display the first rendered SVG image
Reproducible Demo
https://codesandbox.io/s/o45v70nv15
Notes
Is this a bug or am I doing something wrong?
The text was updated successfully, but these errors were encountered: