nivo
nivo copied to clipboard
Warning: Support for defaultProps will be removed from function components
Describe/explain the bug
Getting the following error when using Nivo with Next.js 13 inside app
router:
app-index.js:31 Warning: Jr: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.
It doesn't affect the chart rendering though. It's just a bit annoying to see a long error in the console. Other libraries are also seeing a similar issue:
- https://github.com/recharts/recharts/issues/3615
- https://github.com/chakra-ui/chakra-ui/issues/7057
Wondering if Nivo has a plan to move from defaultProps
to JS default parameters? It seems like quite a large refactor. Happy to contribute if needed. Thanks!
To Reproduce Codesandbox: https://codesandbox.io/p/sandbox/frosty-tom-fgddxp
Steps to reproduce the behavior:
- Go to the codesandbox
- Open the preview in a new tab
- Open dev tool console
- See error
Expected behavior Rendering a chart should throw no error.
I'm running into this issue as well. The warning is quite long also, which makes it difficult to parse other logs that appear in the inspector.
I understand this could be a large refactor... If anyone has suggestions for a hack to suppress warnings about this issue temporarily I would really appreciate it ❤️
Any updates on this? Has anyone found a way to hide the warnings?
I tried to do the refactor (based in the similar issue that @donfour linked to the description) but the deploy has failed and I guess I don't have access to vercel to see the logs :(
I fixed that by patching the console.log
, since the warning is polluting the developer experience.
(And for me, the issue is just occurring in external libraries)
if (process.env.NODE_ENV !== "production") {
// eslint-disable-next-line no-console
const originalWarn = console.error;
// eslint-disable-next-line no-console
console.error = (...args) => {
if (
args[0].includes(
"Support for defaultProps will be removed from function components in a future major release.",
)
) {
return;
}
originalWarn(...args);
};
}
Hello!
Any update on this issue?
@ClydSpyd it's waiting for a release! @plouc Any plans to release a new version soon? Is there something I can help?
Sorry, I just didn't have the time to release, I'll try to find some time in the upcoming weeks.
I fixed that by patching the
console.log
, since the warning is polluting the developer experience. (And for me, the issue is just occurring in external libraries)if (process.env.NODE_ENV !== "production") { // eslint-disable-next-line no-console const originalWarn = console.error; // eslint-disable-next-line no-console console.error = (...args) => { if ( args[0].includes( "Support for defaultProps will be removed from function components in a future major release.", ) ) { return; } originalWarn(...args); }; }
@dreampulse where did you put this code for it to work?
I noticed the warning message only appears locally and not in production. (ReCharts)
Something similar is happening at https://github.com/recharts/recharts/issues/3615
const originalConsoleError = console.error;
console.error = (message, ...args) => {
if (typeof message === 'string' && message.includes('defaultProps will be removed')) {
return;
}
originalConsoleError.apply(console, [message, ...args])
}
Done
This issue has been fixed in the latest version (0.87.0
).