-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. at {Component} #3615
Comments
Thanks, noted! Unfortunately moving away from defaultProps causes unintended bugs due to the way recharts works. But this is known and we're trying to get away from them where we can. Edit: see solution in 2.x #3615 (comment) |
FYI this also happens for the Tooltip component |
Reference for why this is an issue #3438 (comment) |
@akamfoad all of our functional refactors are going to have this issue. We may have to prepared to handle soon as I'm going to release 2.7. Let me know if you have any thoughts |
@ckifer But I think the sooner we embrace JS default params the better, I see many teams are going in this direction, especially those who use TypeScript, I see that is quite the default practice. This is not going to break semver if we do it in v2, because we just change how we receive the default values, internally, for the users of the library everything will be the same and the warning goes away. What do you think? |
@akamfoad I totally agree, but we still have the cloneElement issue linked above (#3438 (comment)). I believe all of the components we have refactored besides Tooltip are safe from that issue so we should be able to move them over |
I believe this list holds those that we cannot touch without fear of breaking things |
So only those components will cause issue if defaultProps is removed, that another component/function needs to access them, including I'm guessing there is a lot of them, especially those from the list in Which means they in fact cause breaking change, when migrated to default params. So we might need to hold off here and revert the Tooltip refactor, that is an easy one. The warning is shown only for Functional Components with defaultProps, but the default behavior may changes in the future for how this affects components (if I understood the RFC correctly). Which means, its probably for the best to prepare for v3. |
Btw @ckifer I think its probably for the best, this might encourage us to have major version (not very soon tho), where we internally do not rely on defaultProps, or cloneElement, instead we use normal JS default params, and renderProps (which is not my personal favorite), or Context API. This way, the children can both render and subscribe to context's provided by the charts (or a an HoC) parent and render, clutter-free |
Thanks for the thoughts @akamfoad! Yeah I agree - I've been shying away from 3.x because it's a lot of work and there's a lot of breaking changes we need to merge in and document but there hasn't really been any meaningful progress made towards it. But yes we definitely need to 100% rid ourselves of the cloneElement approach, it's the cause of a lot of issues (but it's also some of the magic of recharts which is why it's tough to remove or at least tough to test once you remove it). |
No solution yet but we're aware of it, thanks |
I also need the solution asap, do your job devs. |
There are no devs that work on this project as a job. Please feel free to contribute. |
Just leaving this here: const error = console.error;
console.error = (...args: any) => {
if (/defaultProps/.test(args[0])) return;
error(...args);
}; |
Hi, is this a temporary fix that we can implement for now? |
@ooanishoo This will just hide the warning, but there's not really anything else you can do until it's fixed upstream anyway. |
Having the same issue. Is there an update on where this might be fixed? |
I was just about to ask a question, but I guess I won't. Everyone knows 🤣 |
No update really besides some noodling in my head to try to pick a path forwards. If I work on anything at all next it will be this, I just can't make time for it right now as other (life) priorities prevail. |
Risky elements are defined (by me at least 😅 ) as any that are referenced by a call to
All other components outside of these should be able to be refactored to use default params with relative certainty they won't break things. This makes this issue actionable and means that If anyone wants to take the changes or the change for one component let me know. |
Text refactored in #3670. Curve is open for contribution as well as any others that may currently have issue |
Removing defaultProps do not make any sense by the React team. So I think that you should one an issue on the React repository. |
defaultProps will stay on class components. This warning is about defaultProps on functional components. So we could technically solve this by rewriting everything from functional components to classes. But that also means rewriting all hooks. |
That does not make any sense. Using classes is going back in time, and it is an old pattern. We can have functions with defaultProps. |
Alpha release - https://www.npmjs.com/package/recharts/v/2.13.0-alpha.0 Please use this alpha to see if defaultProps warnings are gone (and make sure things are still working as normal in R18 and below). For now, all the function components with issues have been wrapped with classes (while we work on 3.x) |
Works perfectly with R18, console errors disappear and no broken things found. Great job and thanks a lot. |
Nice! All credit to @eps1lon for the interim solution. Work still needed for things not to break in R19 so I'll wait for more feedback and see if we can get full support in before resolving this. Thanks everyone. |
https://www.npmjs.com/package/recharts/v/2.13.0-alpha.3 Please test this one as well on all React versions 16.8-19 to see if anyone runs into issues. Thanks! 🚀 |
Warning: XAxis: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. |
Try installing the alpha version listed above |
@ckifer it worked! |
Hey y'all, I think installing
[UPDATE]: For React versions above R18, this works perfectly for me |
Console error is gone, thx a lot for the support! |
I'm going to close this since we have a path forwards to remove the errors Solution is Feel free to continue to report any issues found here (or R19 related here) Thanks all |
after installing the alpha version, i started getting an error on my build server about a missing dependency (ajv). had to add the library to package.json to resolve. |
@jewseppi do you mind posting the error here? We don't directly depend on or use Ajv so I'm confused |
Error: Cannot find module 'ajv/dist/compile/codegen'
Node.js v22.2.0 |
I'm also seeing this: ERROR in ./node_modules/recharts/es6/index.js |
The "recharts" version: " |
Okay thanks for the quick response. |
Android Bundled 6042ms C:\Users\MON P C\Desktop\Rappelle\mon-app\node_modules\expo\AppEntry.js (1051 modules) |
@ElhadjBoubacar please upgrade to the alpha version if you want the warning to go away. Will release 2.13 when R19 is released |
This is awesome, thank you all for the hard work!! 🙌 |
i tried downloading alpha but it didnt work console error didnt go away Warning: XAxis: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. |
There's only one implementation, so there can't be some people that this is fixed for and others that it isn't. Please |
Using a library that include recharts v2.6.2 i get the following error in the console.
the charts are rendered normally thou.
The text was updated successfully, but these errors were encountered: