React.memo and React.lazy ignore propTypes
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
PropTypes.*.isRequired
with React.memo
doesn’t get triggered in the console when the required prop is undefined.
import React, { memo } from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";
// ********************************************
// It should appear two propTypes console errors
// ********************************************
// without memo(..): it will throw the propTypes error like it should
const MemoButton = memo(() => {
return <button>Memo Button</button>;
});
MemoButton.propTypes = {
memocolor: PropTypes.string.isRequired
};
// it will throw the error in the console
const Button = () => {
return <button>Button</button>;
};
Button.propTypes = {
color: PropTypes.string.isRequired
};
const rootElement = document.getElementById("root");
ReactDOM.render(
<>
<MemoButton />
<Button />
</>,
rootElement
);
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
// affected versions
"prop-types": "15.6.2",
"react": "16.6.1",
"react-dom": "16.6.1",
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
React v16.6.0: lazy, memo and contextType
Class components can bail out from rendering when their input props are the same using PureComponent or shouldComponentUpdate . Now you can do ......
Read more >How To Avoid Performance Pitfalls in React with memo ...
The memo function will compare props and prevent re-renders if no props change, but in this case the showExplanation prop does change, so...
Read more >React.lazy and React.useMemo Together | by Alexey Gaynulin
memo don't work together — actually, React. useMemo doesn't work when its parent is lazy loaded via React. Suspense. I'm not sure —...
Read more >Top 11 React Performance Optimization Techniques in 2023
1. Windowing or List Virtualization in React Applications · 2. Key Coordination for List Rendering · 3. Lazy loading Images in React ·...
Read more >React.createElement: type is invalid error after bundling and ...
import React from 'react'; import PropTypes from 'prop-types'; ... Symbol.for("react.lazy"):60116,A="function"===typeof ...
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
This turned out to be harder than expected 😅 Fix in https://github.com/facebook/react/pull/14298.
The update to use
react-is
is not yet@latest
; the@latest
release still usesPropTypes.func
.This is the current check on
master
: https://github.com/ReactTraining/react-router/blob/d5979813abcd53f7ab0e518248374c61c22f8e15/packages/react-router/modules/Route.js#L131-L137