This is the code that I am getting the error on. I don’t think there is anything wrong with the code I wrote
import { ReactComponent as LogoutIconSvg } from "../../assets/svg/logout-user.svg";
<button type="button" className={styles.profilemenu__item} style={{ "--icon": "#F94687 " }} onClick={logout}>
<LogoutIconSvg />
Logout
</button>
This is the error I am getting
validateDOMNesting(...): <button> cannot appear as a descendant of <button>.
2
Answers
You can’t directly render svg as a component. You need to render it using
img
tag.And also you’re not importing your svg correctly because svg is a static file, not a component.
Try importing it like below
You cannot render an Svg as a component. To do that, you need to create a component that returns that svg, such as:
Then, you can import and use as:
or,
use the import svg as an image not as a component: