Hello!
I faced a problem playing around with React Hooks and this package.
When dynamic import of the package is used like that:
import("@welldone-software/why-did-you-render").then(whyDidYouRender => {
whyDidYouRender(React, {
onlyLogs: true,
titleColor: "green",
diffNameColor: "darkturquoise"
});
});
the following error occurs:
proxyConsole.js:72 Warning: React has detected a change in the order of Hooks called by Example. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks
Previous render Next render
------------------------------------------------------
1. useState useState
2. undefined useRef
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in Example (at src/index.js:19)
in App (at src/index.js:23)
console.<computed> @ proxyConsole.js:72
i.<computed> @ index.js:27
r @ backend.js:6529
warningWithoutStack @ react-dom.development.js:506
warning @ react-dom.development.js:2628
warnOnHookMismatchInDev @ react-dom.development.js:12860
updateHookTypesDev @ react-dom.development.js:12826
useRef @ react-dom.development.js:13834
useRef @ react.development.js:1472
ko @ whyDidYouRender.min.js:8
eval @ whyDidYouRender.min.js:8
useState @ react.development.js:1462
Example @ index.js? [sm]:4
renderWithHooks @ react-dom.development.js:12938
updateFunctionComponent @ react-dom.development.js:14627
beginWork @ react-dom.development.js:15637
performUnitOfWork @ react-dom.development.js:19312
workLoop @ react-dom.development.js:19352
renderRoot @ react-dom.development.js:19435
performWorkOnRoot @ react-dom.development.js:20342
performWork @ react-dom.development.js:20254
performSyncWork @ react-dom.development.js:20228
interactiveUpdates$1 @ react-dom.development.js:20495
interactiveUpdates @ react-dom.development.js:2170
dispatchInteractiveEvent @ react-dom.development.js:4882
react-dom.development.js:55 Uncaught Invariant Violation: Rendered more hooks than during the previous render.
at invariant (https://jdq0k.csb.app/node_modules/react-dom/cjs/react-dom.development.js:55:15)
at updateWorkInProgressHook (https://jdq0k.csb.app/node_modules/react-dom/cjs/react-dom.development.js:13092:35)
at updateRef (https://jdq0k.csb.app/node_modules/react-dom/cjs/react-dom.development.js:13334:14)
I created an example to show the problem.
If you'll try to change something in the code, it can start working at some point, but if you reload the page, the issue will occure again (I think it is related to CodesandBox work).
Also, I have a project on my local machine with the same package version. When using dynamic import I can see the following error:
because it is an object with a key "default":
and I have to use destructuring to get it:
import("@welldone-software/why-did-you-render").then(({ default: whyDidYouRender }) => {
Don't know why, but in the sandbox the function "To" is taken by default and destructuring is not needed.
I'd like to know, first, how to use dynamic import with the package and with React Hooks (it would be better do not to make the bundle bigger using regular import), second, why the parameter that is taken from the package can be the function itself or the object with "default" key, why are they different. Is that a problem with React support of this feature?
Thanks in advance.