Pass inline SVG as a React support component
1 answer
Yes it is possible. But first, you need to define the Icon component.
// MySvgIcon.js
function MySvgIcon() {
return (<svg xmlns="..."></svg>);
}
Once you have a component, you will need to define another component and use the icon like this:
// AnotherComponent.js
function AnotherComponent({ Icon }) {
return (<div>A nice icon: <Icon /></div>);
}
And you can use them like this:
// OtherComponent.js
function OtherComponent() {
return (<AnotherComponent Icon={MySvgIcon} />);
}
0
source to share