---
title: "Discussion on \"How to use SVG's in React\" | Hashnode"
description: "Discussion on \"How to use SVG's in React\". If you are working with React, chances are pretty high that you will end up using SVG's in your application. Once the need is there, struggle gets real. Which way is the best to follow? Well, it depends a lot. Let me explain how.\nSVG as inline elemen..."
url: "https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to use SVG's in React](https://codinghistorian.hashnode.dev/how-to-use-svgs-in-react?utm_source=hashnode&utm_medium=feed)

If you are working with React, chances are pretty high that you will end up using SVG's in your application. Once the need is there, struggle gets real. Which way is the best to follow? Well, it depends a lot. Let me explain how. SVG as inline elemen...

Jan 24, 2021 · 15 min read · codinghistorian.hashnode.dev  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#svg](https://hashnode.com/tag/svg)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Emin Aydin](https://hashnode.com/@codinghistorian)

@codinghistorian · Berlin

  
[View profile](https://hashnode.com/@codinghistorian)

Full-stack Developer

## Responses 3

Markdown supported · ⌘↵ to post

[Yury](https://hashnode.com/@lol)

[Jan 31, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/6016d77313f0a55761bdf233)

Probably not worth my time to write this but i wanted to try out the editor (and it's buggy lol)

Basically, don't ever do this unless you are actually using dynamic svg in your project. Your code is not reusable and also I think this probably adds more unnecessary computation because react has to diff the dom tree and your complex svg logo data props are now part of that dom tree.

99.9% of the time, you are better off just dropping the svg icon file that you downloaded from the webz into some folder and using a webpack SVG loader. Then, you can simply pass in a custom css `fill` style property to the icon component to change its color or w/e.

Install webpack svg loader

```
npm install @svgr/webpack
```

Update your webpack config

```
{
 test: /\.svg$/,
 use: ['@svgr/webpack']
},
```

Import icons and render them

```
import i_react from './icons/react-icon.svg'
....
<i_react style={fill:"red"}/>
```

that's literally all you have to do.

[Yury](https://hashnode.com/@lol)

[Jan 31, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/6016d77313f0a55761bdf233#reply-6016d8d213f0a55761bdf248)

( u can still use react `memoization` to skip rendering the react rendered svg, but don't do that lol )

[Emin Aydin](https://hashnode.com/@codinghistorian)

[Jan 31, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/6016d77313f0a55761bdf233#reply-601719206f46cc1ff950a82d)

Hey [Yury](https://hashnode.com/@lol),

Thanks a lot for taking the time to reply!

I find it hard to understand how you think the code is not reusable since I literally re-used it there. As you have mentioned, my solution would cause more computation but I would argue if it is unnecessary.

Even though your approach is completely valid, once you need to have more access to the SVG properties, it is not satisfying at all. So it is completely developers responsibility to decide on which way to follow, depending on how they are going to use SVG files in their project. But once again thanks for taking the time and coming up with another approach, I really appreciate it :)

[Yury](https://hashnode.com/@lol)

[Feb 1, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/6016d77313f0a55761bdf233#reply-6017a0dba4a28d1fcefce35d)

[Emin Aydin](https://hashnode.com/@codinghistorian)

Okay sorry, let me clarify. I was just going off of your example, where you only changed the color. This is what most devs (like 99%) will probably do for which you can simply use svg css styling, that is why you would want to treat it like a _reusable icon_

However.... if you indeed want to animate custom svg properties for your logo, I would suggest you use an appropriate library because animating svg props manually without abstractions (like relative positioning and data attributes) is not for beginners ;)

hope this helps! :)

[Aryan Kumar](https://hashnode.com/@ArynKr)

[Jan 28, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/601296a2ea8244735e7a6c83)

You wrote awesome. Really helped. Thanks for the awesome explanation. Loved it. ❤🙌

[Emin Aydin](https://hashnode.com/@codinghistorian)

[Jan 28, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/601296a2ea8244735e7a6c83#reply-601319292e1296101bd58450)

I am happy to hear that it helped you out Aryan :)

[Rutik Wankhade](https://hashnode.com/@rutikwankhade)

[Jan 28, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/601256d68b620b1d6bdf84bb)

I have used SVG directly by importing SVG files. But when the SVG is used at different places, this looks like a more reusable approach. The same goes for emojis too.

😊 Like the react way! Thanks for sharing.

[Emin Aydin](https://hashnode.com/@codinghistorian)

[Jan 28, 2021](https://hashnode.com/posts/how-to-use-svgs-in-react/600d89133fdbb7412625f9c6/comment/601256d68b620b1d6bdf84bb#reply-601275298b620b1d6bdf8747)

Thanks a lot Rutik, glad you liked it :)
