@@ -2,34 +2,7 @@ import React from 'react';
22
33const initialList = [ 'Learn React' , 'Learn GraphQL' ] ;
44
5- const ListWithoutKey = ( ) => {
6- const [ list , setList ] = React . useState ( initialList ) ;
7-
8- const handleClick = event => {
9- setList ( list . slice ( ) . reverse ( ) ) ;
10- } ;
11-
12- return (
13- < div >
14- < ul >
15- { list . map ( ( item , index ) => (
16- < li >
17- < label >
18- < input type = "checkbox" />
19- { item }
20- </ label >
21- </ li >
22- ) ) }
23- </ ul >
24-
25- < button type = "button" onClick = { handleClick } >
26- Reverse List
27- </ button >
28- </ div >
29- ) ;
30- } ;
31-
32- // const ListWithIndex = () => {
5+ // const ListWithoutKey = () => {
336// const [list, setList] = React.useState(initialList);
347
358// const handleClick = event => {
@@ -40,7 +13,7 @@ const ListWithoutKey = () => {
4013// <div>
4114// <ul>
4215// {list.map((item, index) => (
43- // <li key={index} >
16+ // <li>
4417// <label>
4518// <input type="checkbox" />
4619// {item}
@@ -56,4 +29,31 @@ const ListWithoutKey = () => {
5629// );
5730// };
5831
59- export default ListWithoutKey ;
32+ const ListWithUnstableIndex = ( ) => {
33+ const [ list , setList ] = React . useState ( initialList ) ;
34+
35+ const handleClick = event => {
36+ setList ( list . slice ( ) . reverse ( ) ) ;
37+ } ;
38+
39+ return (
40+ < div >
41+ < ul >
42+ { list . map ( ( item , index ) => (
43+ < li key = { index } >
44+ < label >
45+ < input type = "checkbox" />
46+ { item }
47+ </ label >
48+ </ li >
49+ ) ) }
50+ </ ul >
51+
52+ < button type = "button" onClick = { handleClick } >
53+ Reverse List
54+ </ button >
55+ </ div >
56+ ) ;
57+ } ;
58+
59+ export default ListWithUnstableIndex ;
0 commit comments