-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defaultProps
is deprecated for fn components
#126
Comments
Indeed, we should add an option that skips adding the defaultProps, and uses inline defaulting in the function body instead (we can't use parameter default syntax or |
Good to read that this issue will be addressed. Any idea when a fix will be released? |
Presumably when someone files a PR adding that option (not a fix, because nothing’s broken, especially since react 19 isn’t even out yet) |
While it is technically true that nothing is broken, those using this plugin to compile their SVG now have their console chock-full of warnings, which makes it harder to see the more useful content in there. Which is not to say that a call for a PR isn't fair :) |
My job has a script that will fail any tests if they throw unaddressed warnings, so this has actually caused pretty big problems for me. |
when I opened the issue I took a little look into how to solve.. but like, I don't really know what level of compatibility is wanted for this one, but if we can use const defaultProps = SVG_DEFAULT_PROPS_CODE
? `const props = Object.assign({}, SVG_DEFAULT_PROPS_CODE, overrides)`
: `const props = overrides`;
const namedTemplate = `
var SVG_NAME = function SVG_NAME(overrides) { ${defaultProps}; return SVG_CODE; };
${IS_EXPORT ? 'export { SVG_NAME };' : ''}
`;
const anonymousTemplate = `
var Component = function (overrides) { ${defaultProps}; return SVG_CODE; };
Component.displayName = 'EXPORT_FILENAME';
export default Component;
`; for: https://github.com/airbnb/babel-plugin-inline-react-svg/blob/master/src/index.js#L29-L39 |
Drop defaultProps from the generated component as they are now deprecated and will be removed in React 19. They were added in airbnb#8 due to concerns about the overhead of `_extends` although no benchmarks were provided and it is likely that difference would be marginal where it matters. Fixes: airbnb#126
I used I'd wonder what other's mileage looks like with this in place |
@ghost1face I ended up just putting |
Message from react: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead
https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-react-apis
The text was updated successfully, but these errors were encountered: