@@ -94,7 +94,7 @@ describe('ReactFunctionComponent', () => {
94
94
} ;
95
95
96
96
getChildContext ( ) {
97
- return { test : this . props . test } ;
97
+ return { test : this . props . test } ;
98
98
}
99
99
100
100
render ( ) {
@@ -122,7 +122,7 @@ describe('ReactFunctionComponent', () => {
122
122
function FunctionComponentWithChildContext ( ) {
123
123
return null ;
124
124
}
125
- FunctionComponentWithChildContext . getDerivedStateFromProps = function ( ) { } ;
125
+ FunctionComponentWithChildContext . getDerivedStateFromProps = function ( ) { } ;
126
126
127
127
const container = document . createElement ( 'div' ) ;
128
128
@@ -133,7 +133,7 @@ describe('ReactFunctionComponent', () => {
133
133
} ) ;
134
134
} ) . toErrorDev (
135
135
'FunctionComponentWithChildContext: Function ' +
136
- 'components do not support getDerivedStateFromProps.' ,
136
+ 'components do not support getDerivedStateFromProps.' ,
137
137
) ;
138
138
} ) ;
139
139
@@ -155,12 +155,12 @@ describe('ReactFunctionComponent', () => {
155
155
} ) ;
156
156
} ) . toErrorDev (
157
157
'FunctionComponentWithChildContext(...): childContextTypes cannot ' +
158
- 'be defined on a function component.' ,
158
+ 'be defined on a function component.' ,
159
159
) ;
160
160
} ) ;
161
161
162
162
it ( 'should not throw when stateless component returns undefined' , async ( ) => {
163
- function NotAComponent ( ) { }
163
+ function NotAComponent ( ) { }
164
164
const container = document . createElement ( 'div' ) ;
165
165
const root = ReactDOMClient . createRoot ( container ) ;
166
166
await expect (
@@ -189,13 +189,13 @@ describe('ReactFunctionComponent', () => {
189
189
__DEV__
190
190
? 'Function components cannot have string refs. We recommend using useRef() instead.'
191
191
: // It happens because we don't save _owner in production for
192
- // function components.
193
- 'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
194
- ' the following reasons:\n' +
195
- '1. You may be adding a ref to a function component\n' +
196
- "2. You may be adding a ref to a component that was not created inside a component's render method\n" +
197
- '3. You have multiple copies of React loaded\n' +
198
- 'See https://reactjs.org/link/refs-must-have-owner for more information.' ,
192
+ // function components.
193
+ 'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
194
+ ' the following reasons:\n' +
195
+ '1. You may be adding a ref to a function component\n' +
196
+ "2. You may be adding a ref to a component that was not created inside a component's render method\n" +
197
+ '3. You have multiple copies of React loaded\n' +
198
+ 'See https://reactjs.org/link/refs-must-have-owner for more information.' ,
199
199
) ;
200
200
} ) ;
201
201
@@ -222,14 +222,14 @@ describe('ReactFunctionComponent', () => {
222
222
} ) ;
223
223
} ) . toErrorDev (
224
224
'Warning: Function components cannot be given refs. ' +
225
- 'Attempts to access this ref will fail. ' +
226
- 'Did you mean to use React.forwardRef()?\n\n' +
227
- 'Check the render method ' +
228
- 'of `ParentUsingStringRef`.\n' +
229
- ' in FunctionComponent (at **)\n' +
230
- ' in div (at **)\n' +
231
- ' in Indirection (at **)\n' +
232
- ' in ParentUsingStringRef (at **)' ,
225
+ 'Attempts to access this ref will fail. ' +
226
+ 'Did you mean to use React.forwardRef()?\n\n' +
227
+ 'Check the render method ' +
228
+ 'of `ParentUsingStringRef`.\n' +
229
+ ' in FunctionComponent (at **)\n' +
230
+ ' in div (at **)\n' +
231
+ ' in Indirection (at **)\n' +
232
+ ' in ParentUsingStringRef (at **)' ,
233
233
) ;
234
234
235
235
// No additional warnings should be logged
@@ -264,14 +264,14 @@ describe('ReactFunctionComponent', () => {
264
264
} ) ;
265
265
} ) . toErrorDev (
266
266
'Warning: Function components cannot be given refs. ' +
267
- 'Attempts to access this ref will fail. ' +
268
- 'Did you mean to use React.forwardRef()?\n\n' +
269
- 'Check the render method ' +
270
- 'of `ParentUsingFunctionRef`.\n' +
271
- ' in FunctionComponent (at **)\n' +
272
- ' in div (at **)\n' +
273
- ' in Indirection (at **)\n' +
274
- ' in ParentUsingFunctionRef (at **)' ,
267
+ 'Attempts to access this ref will fail. ' +
268
+ 'Did you mean to use React.forwardRef()?\n\n' +
269
+ 'Check the render method ' +
270
+ 'of `ParentUsingFunctionRef`.\n' +
271
+ ' in FunctionComponent (at **)\n' +
272
+ ' in div (at **)\n' +
273
+ ' in Indirection (at **)\n' +
274
+ ' in ParentUsingFunctionRef (at **)' ,
275
275
) ;
276
276
expect ( ref ) . not . toHaveBeenCalled ( ) ;
277
277
@@ -287,7 +287,7 @@ describe('ReactFunctionComponent', () => {
287
287
// When owner uses JSX, we can use exact line location to dedupe warnings
288
288
class AnonymousParentUsingJSX extends React . Component {
289
289
render ( ) {
290
- return < FunctionComponent name = "A" ref = { ( ) => { } } /> ;
290
+ return < FunctionComponent name = "A" ref = { ( ) => { } } /> ;
291
291
}
292
292
}
293
293
@@ -317,7 +317,7 @@ describe('ReactFunctionComponent', () => {
317
317
render ( ) {
318
318
return React . createElement ( FunctionComponent , {
319
319
name : 'A' ,
320
- ref : ( ) => { } ,
320
+ ref : ( ) => { } ,
321
321
} ) ;
322
322
}
323
323
}
@@ -346,7 +346,7 @@ describe('ReactFunctionComponent', () => {
346
346
render ( ) {
347
347
return React . createElement ( FunctionComponent , {
348
348
name : 'A' ,
349
- ref : ( ) => { } ,
349
+ ref : ( ) => { } ,
350
350
} ) ;
351
351
}
352
352
}
@@ -391,7 +391,7 @@ describe('ReactFunctionComponent', () => {
391
391
} ;
392
392
}
393
393
render ( ) {
394
- return < Child ref = { function ( ) { } } /> ;
394
+ return < Child ref = { function ( ) { } } /> ;
395
395
}
396
396
}
397
397
@@ -403,12 +403,12 @@ describe('ReactFunctionComponent', () => {
403
403
} ) ;
404
404
} ) . toErrorDev (
405
405
'Warning: Function components cannot be given refs. ' +
406
- 'Attempts to access this ref will fail. ' +
407
- 'Did you mean to use React.forwardRef()?\n\n' +
408
- 'Check the render method ' +
409
- 'of `Parent`.\n' +
410
- ' in Child (at **)\n' +
411
- ' in Parent (at **)' ,
406
+ 'Attempts to access this ref will fail. ' +
407
+ 'Did you mean to use React.forwardRef()?\n\n' +
408
+ 'Check the render method ' +
409
+ 'of `Parent`.\n' +
410
+ ' in Child (at **)\n' +
411
+ ' in Parent (at **)' ,
412
412
) ;
413
413
} ) ;
414
414
@@ -425,18 +425,15 @@ describe('ReactFunctionComponent', () => {
425
425
} ) ;
426
426
} ) . toErrorDev (
427
427
'Each child in a list should have a unique "key" prop.\n\n' +
428
- 'Check the render method of `Child`.' ,
428
+ 'Check the render method of `Child`.' ,
429
429
) ;
430
430
} ) ;
431
431
432
- // TODO: change this test after we deprecate default props support
433
- // for function components
434
- it ( 'should support default props and prop types' , async ( ) => {
432
+ it ( 'should support default props' , ( ) => {
435
433
function Child ( props ) {
436
434
return < div > { props . test } </ div > ;
437
435
}
438
- Child . defaultProps = { test : 2 } ;
439
- Child . propTypes = { test : PropTypes . string } ;
436
+ Child . defaultProps = { test : 2 } ;
440
437
441
438
await expect ( async ( ) => {
442
439
const container = document . createElement ( 'div' ) ;
@@ -447,9 +444,6 @@ describe('ReactFunctionComponent', () => {
447
444
} ) ;
448
445
} ) . toErrorDev ( [
449
446
'Warning: Child: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.' ,
450
- 'Warning: Failed prop type: Invalid prop `test` of type `number` ' +
451
- 'supplied to `Child`, expected `string`.\n' +
452
- ' in Child (at **)' ,
453
447
] ) ;
454
448
} ) ;
455
449
@@ -461,7 +455,7 @@ describe('ReactFunctionComponent', () => {
461
455
} ;
462
456
463
457
getChildContext ( ) {
464
- return { lang : 'en' } ;
458
+ return { lang : 'en' } ;
465
459
}
466
460
467
461
render ( ) {
@@ -472,7 +466,7 @@ describe('ReactFunctionComponent', () => {
472
466
function Child ( props , context ) {
473
467
return < div > { context . lang } </ div > ;
474
468
}
475
- Child . contextTypes = { lang : PropTypes . string } ;
469
+ Child . contextTypes = { lang : PropTypes . string } ;
476
470
477
471
const el = document . createElement ( 'div' ) ;
478
472
@@ -484,7 +478,7 @@ describe('ReactFunctionComponent', () => {
484
478
} ) ;
485
479
486
480
it ( 'should work with arrow functions' , async ( ) => {
487
- let Child = function ( ) {
481
+ let Child = function ( ) {
488
482
return < div /> ;
489
483
} ;
490
484
// Will create a new bound function without a prototype, much like a native
@@ -501,7 +495,7 @@ describe('ReactFunctionComponent', () => {
501
495
} ) ;
502
496
503
497
it ( 'should allow simple functions to return null' , async ( ) => {
504
- const Child = function ( ) {
498
+ const Child = function ( ) {
505
499
return null ;
506
500
} ;
507
501
await expect ( async ( ) => {
0 commit comments