Passing Functions as Props
Lists and Keys
- What does .map() return?
- .map() returns a new array
- If I want to loop through an array and display each value in JSX, how do I do that in React?
- wrap the js code with {} and then use .map(num => <>{num}</>) to render it
- Each list item needs a unique __.
- What is the purpose of a key?
- Keys help React identify which items have changed, are added, or are removed.
The Spread Operator
- What is the spread operator?
- a useful and quick syntax for adding items to arrays, combining arrays or objects, and spreading an array out into a function’s arguments
- List 4 things that the spread operator can do.
- Copying an array
- Concatenating or combining arrays
- Using Math functions
- Using an array as arguments
- Give an example of using the spread operator to combine two arrays.
const arr3 = {...arr1,...arr2}
- Give an example of using the spread operator to add a new item to an array.
arr1 = [...arr1, newNumber]
- Give an example of using the spread operator to combine two objects into one.
const objectThree = {...objectOne, ...objectTwo}
More on lists and keys
More on the spread operator
<==Back