Skip to content
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

How to use it with React.memo ? #9

Closed
vaynevayne opened this issue Apr 13, 2023 · 1 comment
Closed

How to use it with React.memo ? #9

vaynevayne opened this issue Apr 13, 2023 · 1 comment

Comments

@vaynevayne
Copy link

When using memo, it needs to be packaged many times. It is too verbose. Can it be optimized?

export default InternalDemo = memo(()=> <></>) 
const InternalDemo = ()=> <></>

// ❌
export default memo(InternalDemo) 

// ✅
const Demo =  memo(InternalDemo) 
export default Demo
@ArnaudBarre
Copy link
Owner

Nope the limitation is wanted so that each component to have a name, so stacktraces and devtools are not filled with "anonymous components".

Plus the verbose part comes from using a default export, which has a lot a bad things with (grep can miss usage, not nice when exporting multiple components per files and extra line). The only benefit is that you can use with React.lazy, which is the edge case for most components

export const Demo = memo(InternalDemo) 

or

export const Demo = memo(function InternalDemo () {
  ...
}) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants