question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Svg will crack when import with ReactComponent

See original GitHub issue

I have several needs to hover a button and change color of the svg path stroke/fill It will work perfectly most of time I use it as a component can assign a classname. While sometimes the svg image will crack and I sure it is complete when I use it as I think it is a bug, thanks for help

FYI svg source : https://reurl.cc/8yAkX

Import {ReactComopnent as Graph } from ‘…/.svg’

render() …

<div> < Graph/> </div>

npm 6.4.1 react 16.6.0


Thanks for your patient 😃 I finally get a simple one. Here is the code :

import React, { Component } from 'react';
import './App.css';
import {ReactComponent as A } from './A.svg'
import  {ReactComponent as B } from './B.svg'
class App extends Component {
  render() {
    return (
      <div className="App">
       <A/>
       <B/>
      </div>
    );
  }
}
export default App;

and FYI here is those 2 svg https://reurl.cc/ZGlzg https://reurl.cc/gWnEV

btw, you might need set background color to see it clearly.

This is how it happened : as long as I use them in the same time, one specific svg will crack. In this situation, B will become an incomplete image… like this : Not for every svg. I try to edit svg like delete <defs> and <mask> It works only for another svg…, but not for every svg files. Thanks for help

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:22 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
BipinBhandaricommented, Jan 21, 2020

I agree with @codeheroics. This was quite confusing issue because some svgs were working but some were not.

I solved this problem by using prefix-svgs svgo plugin.

Basically it would convert id to filename prefixed ids.

I added svgo to package.json and I created yarn script as this which would recursively apply this plugin to all svg file: "prefix-svgs":"svgo -f . -r --enable=prefixIds"

4reactions
Waseemrajashaikcommented, Sep 10, 2019

@sartios you can check version - https://github.com/facebook/create-react-app/releases/tag/v3.1.0

if you still facing the issue - as i mention above please change svg’s which contain similar id’s id’s should be different

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting undefined when importing svg as ReactComponent in ...
To import an SVG: import MySvg from "MySvg.svg" which will save the ... The reason you get undefined is that you are destructuring...
Read more >
Dynamic SVG Imports in Create-React-App | by Ryan Hutzley
In this post, I will show you how to dynamically import your SVGs in CRA using a custom hook. First, we'll dive into...
Read more >
Why can't I get my LOGO in my APP? How to import SVGs in ...
Let's setup our Next.js app to import SVGs as React components! Get that infinite scalability and easy recolouring More in our "An app ......
Read more >
react-popup-announcement - npm
image.svg"; import Announcement from "react-popup-announcement"; class Example extends React.Component { render() { return ( <Announcement ...
Read more >
[Solved]-How do I add color to my svg image in react-Reactjs
import { ReactComponent as Logo } from './logo.svg'; const App = () => ( <div> {/* Logo is an actual React component */}...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found