Passing Functions as Props
React Docs - lists and keys
- What does .map() return?
- A new array with each element being the result of the callback function.
- If I want to loop through an array and display each value in JSX, how do I do that in React?
- there is many ways, we can use forEach, forLoop and map.
in for loop it will be like this:
let arr = [1,2,3,4,5];
for(let i = 0; i < arr.length; i++){
console.log(arr[i]) ;}
In for Each:
let arr = [1,2,3,4,5];
arr.forEach(element => {
console.log (element);});
in .Map:
let arr = [1,2,3,4,5];
let array = arr.map((element) => {
console.log (element);});
- Each list item needs a unique Key.
- What is the purpose of a key?
- React uses keys to figure out which items have changed, been added to, or been removed. To give the elements in the array a stable identity, keys should be assigned to them. A string that uniquely identifies a list item among its siblings is the best approach to choose a key.
The Spread Operator
- What is the spread operator?
- The spread operator is a convenient and fast way to add items to arrays, combine arrays or objects, and spread an array across a function’s arguments.
- List 4 things that the spread operator can do.
- Copying an array
- Using Math functions
- Combining objects
- Combining objects
- Give an example of using the spread operator to combine two arrays.

- Give an example of using the spread operator to add a new item to an array.

- Give an example of using the spread operator to combine two objects into one.
