Skip to content

@svgr/webpack generates React components with defaultProps, causing warnings in console. how to resolve this? #1005

@Naveen-Bhati

Description

@Naveen-Bhati

When using @svgr/webpack, the generated React components for SVGs still include defaultProps, which results in the following warning in the console when using React.

"Warning: Component.defaultProps is not supported in React future releases. Use JavaScript default parameters instead."

I've tried various approches to reolve but no luck till now.
currently i'm using this config for the svgr/webpack

// svgr.config.js
{
expandProps: ,false
replaceAttrValues: {},
prettier: true,
typescript: true, // if you're using TypeScript
jsxRuntime: 'automatic', // or 'classic' depending on your setup
// Disable defaultProps
svgo: true,
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false,
},
],
},
template: (variables, { tpl }) => {
return tplimport * as React from 'react'; const ${variables.componentName} = ({ title = "default title", ...props }) => ( ${variables.jsx} ); export default ${variables.componentName};;
}
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions