InterviewHubPRO
Section Overview
Q157

Question 157 of 445

Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

35%
React & Modern Frontend (445 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

Can I import an SVG file as react component?

You can import SVG directly as component instead of loading it as a file. This feature is available with react-scripts@2.0.0 and higher.

jsx
import { ReactComponent as Logo } from "./logo.svg";

const App = () => (
<div>
  {/* Logo is an actual react component */}
  <Logo />
</div>
);

Note: Don't forget about the curly braces in the import.