2024-03-04
3311
#react#svg
Nedy Udombat
13242
Mar 4, 2024 â‹… 11 min read

How to use SVGs in React

Nedy Udombat Software engineer.

Recent posts:

Understanding Security In React Native Applications

Understanding security in React Native applications

Explore the various security threats facing React Native mobile applications and how to mitigate them.

Wisdom Ekpotu
Mar 27, 2024 â‹… 10 min read
Warp Adoption Guide: Overview, Examples, And Alternatives

warp adoption guide: Overview, examples, and alternatives

The warp web framework for Rust offers many enticing features. Let’s see when and why you should consider using warp in your projects.

Ukeje Goodness
Mar 26, 2024 â‹… 8 min read
Integrating Next Js And Signalr For Enhanced Real Time Web App Capabilities

Integrating Next.js and SignalR to build real-time web apps

In this tutorial, you’ll learn how to integrate Next.js and SignalR to build an enhanced real-time web application.

Clara Ekekenta
Mar 25, 2024 â‹… 8 min read
Exploring Tailwind Oxide

Exploring Tailwind Oxide

Tailwind Oxide was introduced to address common issues that exist with Tailwind CSS, such as the complex setup process.

Marie Starck
Mar 22, 2024 â‹… 5 min read
View all posts

11 Replies to "How to use SVGs in React"

  1. I tried this, but the SVG doesn’t show when using an image tag. I don’t know what I am missing. I installed file-loader, too.

  2. Great article! One usage not mentioned above, using as inline background image:
    .elem {
    background-image: url(‘data:image/svg+xml, ……’);
    }

  3. I second, this is a great article!
    Would also like to add the the object tag can be used (…)

    But, more important – this article does not relate the fact that some of the methods listed here inline the SVG into the DOM – which allows developers to use CSS and JS to manipulate the SVG which is amazing !

  4. You can use something like react-app-rewired to provide access to a webpack config file without ejecting.

  5. “export ‘ReactComponent’ (imported as ‘ReactLogo’) was not found in ‘../static/images/icon/svg/feather–white.svg’
    i go this error messages after using ReactComponent step, what should i do?

  6. If you’re using CRA just import it as a component like in the example. All the SVGR business is handled for you already

  7. “Then we update our Webpack configuration rule to use SVGR for SVGs”. What file is that? With witch name I need to create it?

  8. “ With this, we can already see the disadvantage of using this method, when the image is more complex the SVG file becomes larger and since SVG is stored in text, that means we have a whole bunch of text in our code.”

    What are the disadvantages? Is it solely the amount of text in the code? Or is there another disadvantage?

  9. Thanks for sharing mate! Using SVG as a component worked like dream for me. One cool thing is that it creates an inline SVG which to which we can pass props such as className and control its presentation that way.

Leave a Reply