Skip to content
Advertisement

Best way to include reusable SVG in React

I am including SVG as reusable component on my react application. Sample of SVG component is as follows

JavaScript

On page level, I am importing IconComponent and reusing it. Is there any other best way to include reusable SVGs in React pages which improves performance/page load?

Advertisement

Answer

1. SVG with webpack

command line

JavaScript

webpack.config.js

JavaScript

then

JavaScript

2. SVG as component

JavaScript

also you can use props like this.

3. SVG as path

JavaScript

I hope these codes will help you. Personally, I recommend the second method.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement