From c9e026733e11b131542b479fce0b79326618dbb7 Mon Sep 17 00:00:00 2001 From: Kanish Bodhwani <64742906+kanishbodhwani@users.noreply.github.com> Date: Mon, 17 Oct 2022 23:42:20 +0530 Subject: [PATCH 1/2] Updated React.md --- reactjs.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/reactjs.md b/reactjs.md index aa3887d..5fa5352 100644 --- a/reactjs.md +++ b/reactjs.md @@ -169,3 +169,21 @@ When you click a submit button, usually page gets refreshed. You can prevent thi ```js event.preventDefault(); ``` + +# Lists and Keys + +This is the example of how we can use lists and keys in react. +We loop through the numbers array using the JavaScript map() function. We return a `
  • ` element for each item. Finally, we assign the resulting array of elements to listItems + +```js +const numbers = [10, 20, 30, 40, 50]; +const listItems = numbers.map((number) => +
  • {number}
  • +); +``` + +Then, we can include the entire listItems array inside a `