Categories
React Answers

How to embed SVG into React?

Spread the love

Sometimes, we want to embed SVG into React.

In this article, we’ll look at how to embed SVG into React.

How to embed SVG into React?

To embed SVG into React, we can import the svg file with import.

For instance, we write

import chatSVG from "../assets/chat.svg";

to import the chat.svg file with import.

Then we add the chatSVG img element by writing

<img src={chatSVG} className="iconChat" alt="chat" />;

We set the src prop to chatSVG to load the SVG in our component.

Conclusion

To embed SVG into React, we can import the svg file with import.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *