0

i m trying to use SVG with react, but i can t.i tried some solution, result i didn't find why i get this error:

InvalidCharacterError
Failed to execute 'createElement' on 'Document': The tag name provided ('<svg>
<g transform="translate(0.000000,227.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<

if there anyone who can help me i will be very thankful. example of the code in codesandbox : https://codesandbox.io/s/svg-in-react-r3g6l?file=/index.js

1
  • 1
    You need to include the code in the question itself. Commented Jun 20, 2020 at 0:21

3 Answers 3

2

This is what I usually do:

Visit https://react-svgr.com/playground/ and paste in your SVG and it will transform the SVG into React component. It lets you pass SVG attributes as props.

You may check out its original library - svgr for other usages.

Sign up to request clarification or add additional context in comments.

Comments

0

you should use the img tag

import Logo from "./Logo.svg
<img src={Logo} alt="Logo" />

2 Comments

thank you for your response , so how can u change the color of the svg ?
I see that on the sandbox you have react and react-dom version 16.0.0. have you tried updating to 16.4 or above?
0

"As part of features added to the new version of create-react-app (v2), we can now import SVGs as React components."

Check this article for more options: using-svg-icons-components-in-react

*Edit: to change the color of the svg, use the 'fill' propery in CSS. You can add id or class inside your svg to select it.

fill: red;

1 Comment

thank u man about ur explication , currently i m using react boilerpate not create react app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.