Memo + ForwardRef = false positive?
See original GitHub issueEslint 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:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top 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 >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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:If it only happens with the combination - ie, with memo and forwardRef, but not just with forwardRef - then it’s definitely a bug.