Responsive SVGs in React
July 15, 2019
tl;dr: You need to import the responsive svg as a ReactComponent
Firstly, you need a responsive SVG. And then you need to inport it as a ReactComponent in React
code
import React from "react";
import logo from "/images/notes/reactjs/logo-responsive.svg";
import { ReactComponent as Logo } from "/images/notes/reactjs/logo-responsive.svg";
function Demo() {
return (
<div className="App-body">
<main>
<h1>Responsive SVG Demo</h1>
{/* the img will show but will not be responsive */}
<img src={logo} alt="logo" />
{/* the ReactComponent will be a respnsive SVG, but it'll add the entire SVG,
i.e. ALL the <symbol>s you defined will be in the code */}
<Logo />
</main>
</div>
);
}
export default Demo;