2025-04-10
4360
#react#svg
Nedy Udombat
13242
116
Apr 10, 2025 â‹… 15 min read

A guide to using SVGs in React

Nedy Udombat Software engineer.

Recent posts:

best JavaScript and HTML5 game engines

Best JavaScript and HTML5 game engines (updated for 2025)

Check out this guide, which ranks the top 10 JavaScript/HTML5 game engines by popularity, capability, and use case.

Solomon Eseme
May 2, 2025 â‹… 15 min read

React Compiler RC: What it means for React devs

The React team officially released the first Release Candidate (RC). Let’s go over what’s new in RC and what it means for React developers.

David Omotayo
May 2, 2025 â‹… 7 min read
Understanding Anthropic's Model Context Protocol (MCP)

Understanding Anthropic’s Model Context Protocol (MCP)

The Model Context Protocol (MCP) provides a standardized way for AI models to access contextual information from diverse data sources.

David Omotayo
May 2, 2025 â‹… 12 min read
Choosing The Best Access Control Model For Your Frontend

Choosing the best access control model for your frontend

Explore RBAC, ABAC, ACL, and PBAC access control methods and discover which one is ideal for your frontend use case.

Temitope Oyedele
May 1, 2025 â‹… 10 min read
View all posts

12 Replies to "A guide to using 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.

  10. I use SVG over raster images where possible because of flex box designs, they look good at all screen sizes. I don’t think that “Passing as an SVG string” is a good idea, But having said that it could be possible to create a file with lots of SVG strings then just import them directly from a Module as a const.

Leave a Reply