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:

Using React Shepherd To Build A Site Tour

Using React Shepherd to build a site tour

React Shepherd stands out as a site tour library due to its elegant UI and out-of-the-box, easy-to-use React Context implementation.

Onuorah Bonaventure
May 1, 2024 â‹… 14 min read
A Guide To Cookies In Next Js

A guide to cookies in Next.js

Cookies are crucial to web development. This article will explore how to handle cookies in your Next.js applications.

Georgey V B
Apr 30, 2024 â‹… 10 min read
Handling Dates In JavaScript With Tempo

Handling dates in JavaScript with Tempo

Use the Tempo library to format dates and times in JavaScript while accounting for time zones, daylight saying time, and date internationalization.

Amazing Enyichi Agu
Apr 30, 2024 â‹… 8 min read
A Guide To Deno.cron

A guide to Deno.cron

This guide explores how to use the cron package in Deno, `Deno.cron`, to handle scheduling tasks with specific commands.

Rosario De Chiara
Apr 29, 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