Skip to content

Commit

Permalink
🔐 Index as key
Browse files Browse the repository at this point in the history
Index as key
  • Loading branch information
SaishJ committed Sep 2, 2022
1 parent 017b8b8 commit 902d326
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,5 @@ export default ClassClick;
### [Conditional Rendering](https://github.com/SaishJ/React-JS-Beginner-to-Advanced/blob/master/src/components/UserGreeting.js)

### [List Rendering](https://github.com/SaishJ/React-JS-Beginner-to-Advanced/commit/d7d48445fa9578b28fb68fc50e5cecbf5d78132d#diff-da356e7f0ec06b582f616a27e404266469bc463344c1378741025425ddf6611c)

### [List and Keys](https://github.com/SaishJ/React-JS-Beginner-to-Advanced/commit/017b8b8f7a3121cb1efbeb6bb87b3712ed1e10a0)
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import EvenBind from "./components/EventBind";
import ParentComponent from "./components/ParentComponent";
import UserGreeting from "./components/UserGreeting";
import PersonList from "./components/PersonList";
import NameList from "./components/NameList";

function App() {
return (
<div className="App">
<PersonList />
<NameList />
{/* <PersonList /> */}
{/* <UserGreeting /> */}
{/* <ParentComponent /> */}
{/* <EvenBind /> */}
Expand Down
18 changes: 18 additions & 0 deletions src/components/NameList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

function NameList() {
const data = ["Ironman", "Spiderman", "Batman"];
let lists = data.map((data, index) => (
<h2 key={index}>
{index} {data}
</h2>
));
return <div>{lists}</div>;
}

export default NameList;

// When to use index as key:
// 1) The items in your list do not have a unique id.
// 2) The list is a static list and will not change.
// 3) The list will never be reordered or filtered.

0 comments on commit 902d326

Please sign in to comment.