ArnaudBarre / eslint-plugin-react-refresh

Validate that your components can safely be updated with Fast Refresh
MIT License
206 stars 13 forks source link

How to use it with React.memo ? #9

Closed vaynevayne closed 1 year ago

vaynevayne commented 1 year ago

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 commented 1 year ago

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 () {
  ...
})