question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memo + ForwardRef = false positive?

See original GitHub issue

Eslint complains about myProp being missing in prop validation when a forwardRef’d component is memoized.

const myComponent = memo(forwardRef( ({ myProp }, ref) => {
....
}

If I add myProp to prop validation.

const myComponent = ({ myProp }, ref) => {
....
}
myComponent.propTypes = { myProp: PropTypes.number.isRequired }
default export memo(forwardRef(myComponent));

Then eslint stops complaining, but now the site wont render:

Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component?

Is there someway to use memo and forwardRef that eslint doesn’t complain about?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
yannickcrcommented, Jul 22, 2019

Having multiple wrapper was not supported, it should be fixed in v7.14.3. Thanks for the report 🙂

Also you must add the propTypes to the final component:

const myComponent =  memo(forwardRef(({ myProp }, ref) => {
  // ...
}))
myComponent.propTypes = { myProp: PropTypes.number.isRequired }
default export myComponent;
1reaction
ljharbcommented, Jul 16, 2019

If it only happens with the combination - ie, with memo and forwardRef, but not just with forwardRef - then it’s definitely a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React memo allowing re-rendering to forwardRef
This has nothing to do with the ref. LzSearch is rerendering because the onUpdate prop is changing. MyComp will need to use useCallback...
Read more >
Bountysource
display-name has false positive on nested use of memo and forwardRef.
Read more >
React forwardRef and memo combo - CodeSandbox
React forwardRef and memo combo - CodeSandbox. {/* Displays "Anonymous [Memo]" in devtools. child and thus be "forwardRefComponentLi.
Read more >
CHANGELOG.md - facebook/react - Sourcegraph
Fix the false positive warning about react-dom/client when using UMD bundle. ... (@gaearon in #19464); Throw if forwardRef or memo component returns ...
Read more >
تويتر \ дэн على تويتر: "@theKashey I'll be building out the ...
... Component =! <Component/>.type - dev tools integration - false positive HMR updates ... memo, lazy, forwardRef react-hot-loader@next - React15,16,Fusion ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found