@@ -455,6 +455,22 @@ ruleTester.run('display-name', rule, {
455
455
456
456
export default React.memo(Component)
457
457
`
458
+ } , {
459
+ code : `
460
+ import React from 'react'
461
+
462
+ const ComponentWithMemo = React.memo(function Component({ world }) {
463
+ return <div>Hello {world}</div>
464
+ })
465
+ `
466
+ } , {
467
+ code : `
468
+ import React from 'react'
469
+
470
+ const ForwardRefComponentLike = React.forwardRef(function ComponentLike({ world }, ref) {
471
+ return <div ref={ref}>Hello {world}</div>
472
+ })
473
+ `
458
474
} , {
459
475
code : `
460
476
function F() {
@@ -684,6 +700,94 @@ ruleTester.run('display-name', rule, {
684
700
errors : [ {
685
701
message : 'Component definition is missing display name'
686
702
} ]
703
+ } , {
704
+ code : `
705
+ import React from 'react'
706
+
707
+ const ComponentWithMemo = React.memo(({ world }) => {
708
+ return <div>Hello {world}</div>
709
+ })
710
+ ` ,
711
+ errors : [ {
712
+ message : 'Component definition is missing display name'
713
+ } ]
714
+ } , {
715
+ code : `
716
+ import React from 'react'
717
+
718
+ const ComponentWithMemo = React.memo(function() {
719
+ return <div>Hello {world}</div>
720
+ })
721
+ ` ,
722
+ errors : [ {
723
+ message : 'Component definition is missing display name'
724
+ } ]
725
+ } , {
726
+ code : `
727
+ import React from 'react'
728
+
729
+ const ForwardRefComponentLike = React.forwardRef(({ world }, ref) => {
730
+ return <div ref={ref}>Hello {world}</div>
731
+ })
732
+ ` ,
733
+ errors : [ {
734
+ message : 'Component definition is missing display name'
735
+ } ]
736
+ } , {
737
+ code : `
738
+ import React from 'react'
739
+
740
+ const ForwardRefComponentLike = React.forwardRef(function({ world }, ref) {
741
+ return <div ref={ref}>Hello {world}</div>
742
+ })
743
+ ` ,
744
+ errors : [ {
745
+ message : 'Component definition is missing display name'
746
+ } ]
747
+ } , {
748
+ // Only trigger an error for the outer React.memo
749
+ code : `
750
+ import React from 'react'
751
+
752
+ const MemoizedForwardRefComponentLike = React.memo(
753
+ React.forwardRef(({ world }, ref) => {
754
+ return <div ref={ref}>Hello {world}</div>
755
+ })
756
+ )
757
+ ` ,
758
+ errors : [ {
759
+ message : 'Component definition is missing display name'
760
+ } ]
761
+ } , {
762
+ // Only trigger an error for the outer React.memo
763
+ code : `
764
+ import React from 'react'
765
+
766
+ const MemoizedForwardRefComponentLike = React.memo(
767
+ React.forwardRef(function({ world }, ref) {
768
+ return <div ref={ref}>Hello {world}</div>
769
+ })
770
+ )
771
+ ` ,
772
+ errors : [ {
773
+ message : 'Component definition is missing display name'
774
+ } ]
775
+ } , {
776
+ // React does not handle the result of forwardRef being passed into memo
777
+ // ComponentWithMemoAndForwardRef gets shown as Memo(Anonymous)
778
+ // See https://github.com/facebook/react/issues/16722
779
+ code : `
780
+ import React from 'react'
781
+
782
+ const MemoizedForwardRefComponentLike = React.memo(
783
+ React.forwardRef(function ComponentLike({ world }, ref) {
784
+ return <div ref={ref}>Hello {world}</div>
785
+ })
786
+ )
787
+ ` ,
788
+ errors : [ {
789
+ message : 'Component definition is missing display name'
790
+ } ]
687
791
} , {
688
792
code : `
689
793
import React from "react";
0 commit comments