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:

Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 â‹… 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 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