i'm trying to use SVGR to convert my svg into react components and i need to use <SvgIcon />
of Material UI and pass the converted component as a prop to it.
nothing wrong with this yet.
but,
SVGR saves these component in a folder called svgCom for example and inside of this folder there is index.js
plus converted svg components.
i need to wrapp all these components inside of <SvgIcon>
so i don't have to wrap this icon with <SvgIcon/>
again for each use case;
so far i try to add this component in template.js
of SVGR but it throw me an error when try to parse .
is this the best way of doing such thing or there is better way ? if it is what's wrong with my template.js ?
here is my templete.js :
function template(
{ template },
opts,
{ imports, componentName, props, jsx, exports },
) {
return template.ast`
${imports}
import { SvgIcon } from "@material-ui/core";
///////////////////////////////////// error here
const ${componentName} = (${props}) => <SvgIcon component={${jsx}} />
${exports}
`
}
module.exports = template
thank you.
We had the same problem and after some research I came to the following solution:
If you don't want
{...props}
on the<svg>
tag, you have to disable theexpandProps
option