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 [email protected] and higher.
1 2 3 4 5 6 7 8 | 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.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.