File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
react-reconciler/src/__tests__ Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -170,5 +170,25 @@ describe('pure', () => {
170170 expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Old count: 0, New count: 1' , 1 ] ) ;
171171 expect ( ReactNoop . getChildren ( ) ) . toEqual ( [ span ( 1 ) ] ) ;
172172 } ) ;
173+
174+ it ( 'warns for class components' , ( ) => {
175+ class SomeClass extends React . Component {
176+ render ( ) {
177+ return null ;
178+ }
179+ }
180+ expect ( ( ) => pure ( SomeClass ) ) . toWarnDev (
181+ 'pure: The first argument must be a functional component.' ,
182+ { withoutStack : true } ,
183+ ) ;
184+ } ) ;
185+
186+ it ( 'warns if first argument is not a function' , ( ) => {
187+ expect ( ( ) => pure ( ) ) . toWarnDev (
188+ 'pure: The first argument must be a functional component. Instead ' +
189+ 'received: undefined' ,
190+ { withoutStack : true } ,
191+ ) ;
192+ } ) ;
173193 }
174194} ) ;
Original file line number Diff line number Diff line change @@ -17,9 +17,19 @@ export default function pure<Props>(
1717 if ( typeof render !== 'function' ) {
1818 warningWithoutStack (
1919 false ,
20- 'pure requires a render function but was given %s.' ,
20+ 'pure: The first argument must be a functional component. Instead ' +
21+ 'received: %s' ,
2122 render === null ? 'null' : typeof render ,
2223 ) ;
24+ } else {
25+ const prototype = render . prototype ;
26+ if ( ! ! ( prototype && prototype . isReactComponent ) ) {
27+ warningWithoutStack (
28+ false ,
29+ 'pure: The first argument must be a functional component. Classes ' +
30+ 'are not supported. Use React.PureComponent instead.' ,
31+ ) ;
32+ }
2333 }
2434 }
2535 return {
You can’t perform that action at this time.
0 commit comments