Nedy Udombat
Mar 4, 2024 ⋅ 11 min read

How to use SVGs in React

Nedy Udombat Software engineer.

Recent posts:

Expo Router Adoption Guide Overview Examples And Alternatives

Expo Router adoption guide: Overview, examples, and alternatives

Expo Router provides an excellent file-based routing solution with crucial features such as deep linking and native support.

Marie Starck
Jun 13, 2024 ⋅ 8 min read
Superglue Vs. Hotwire For Modern Frontend Development

Superglue vs. Hotwire for modern frontend development

Explore how Superglue and Hotwire revolutionize frontend development with HTML over the wire, enhancing performance, flexibility, and ease of use.

Frank Joseph
Jun 12, 2024 ⋅ 7 min read
Using Pocketbase To Build A Full Stack Application

Using PocketBase to build a full-stack application

PocketBase is a performant Go-based tool that comes with essential features like user auth, file uploads, access control rules, and more.

Rahul Padalkar
Jun 11, 2024 ⋅ 18 min read
The Top Tools For Implementing E-Commerce Search In React

The top tools for implementing e-commerce search in React

Explore top frontend tools for implementing e-commerce search functionality with React demo implementations.

Saleh Mubashar
Jun 10, 2024 ⋅ 7 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