File tree Expand file tree Collapse file tree 1 file changed +47
-1
lines changed
Expand file tree Collapse file tree 1 file changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -41,11 +41,36 @@ function MyComponent () {
4141 <li key = " 1" >Item 1</li >
4242 <li key = " 1" >Item 2</li >
4343 // ^^^^^^^
44- // - A key must be unique. '1 ' is duplicated.
44+ // - A key must be unique. 'key="1" ' is duplicated.
4545 ]
4646};
4747```
4848
49+ ``` tsx
50+ import React from " react" ;
51+
52+ function MyComponent() {
53+ return (
54+ <ul >
55+ <li key = " 1" >Item 1</li >
56+ <li key = " 1" >Item 2</li >
57+ { /* ^^^^^^^ */ }
58+ { /* - A key must be unique. 'key="1"' is duplicated. */ }
59+ </ul >
60+ );
61+ }
62+ ```
63+
64+ ``` tsx
65+ import React from " react" ;
66+
67+ function MyComponent() {
68+ return <ul >{ [" a" , " b" ].map ((id ) => <li key = " 1" >{ id } </li >)} </ul >;
69+ // ^^^^^^^
70+ // - A key must be unique. 'key="1"' is duplicated.
71+ }
72+ ```
73+
4974### Passing
5075
5176``` tsx
@@ -59,6 +84,27 @@ function MyComponent () {
5984};
6085```
6186
87+ ``` tsx
88+ import React from " react" ;
89+
90+ function MyComponent() {
91+ return (
92+ <ul >
93+ <li key = " 1" >Item 1</li >
94+ <li key = " 2" >Item 2</li >
95+ </ul >
96+ );
97+ }
98+ ```
99+
100+ ``` tsx
101+ import React from " react" ;
102+
103+ function MyComponent() {
104+ return <ul >{ [" a" , " b" ].map ((id ) => <li key = { id } >{ id } </li >)} </ul >;
105+ }
106+ ```
107+
62108## Implementation
63109
64110- [ Rule source] ( https://github.com/rEl1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x/src/rules/no-duplicate-key.ts )
You can’t perform that action at this time.
0 commit comments