You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also manually track any component you want by setting whyDidYouRender on them like this:
functionBigListPureComponent(){return<div>
//some heavy component you want to ensure doesn't happen if its not neceserry
</div>}BigListPureComponent.whyDidYouRender=true
In TypeScript, if we want whyDidYouRender be readonly, we should write:
functionBigListPureComponent(){return<div>//some heavy component you want to ensure doesn't happen if its not neceserry</div>}namespaceBigListPureComponent{exportconstwhyDidYouRender=true;}
But CRA doesn't support namespace now.
The text was updated successfully, but these errors were encountered:
As for your issue, these aren't equivalent at all. In fact your second example wouldn't even compile in TypeScript compiler, because in the output it would have to redeclare BigListPureComponent which is a const. It would work if you used function, not const, but still, it's 3 lines of code instead of one and you get additional IIFE in the output for exactly the same effect. There are no upsides to the second solution. Your first example compiles completely fine under strict mode so I personally don't see any reason to meddle with namespaces support.
This is one of the standard USES of namespace.
The standard TypeScript practice for adding readonly attributes to a function instance is to use namespace with export const.
Another reason is that our existing code base, which has a hierarchical relationship and contains both type and value, has already used namespace.
https://github.com/welldone-software/why-did-you-render
In TypeScript, if we want whyDidYouRender be
readonly
, we should write:But CRA doesn't support namespace now.
The text was updated successfully, but these errors were encountered: