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.