View on GitHub

reading-notes

Learning Notes Repo for Code Fellows

Passing Functions as Props

Lists and Keys

  1. What does .map() return?
    • .map() returns a new array
  2. 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
  3. Each list item needs a unique __.
    • key
  4. What is the purpose of a key?
    • Keys help React identify which items have changed, are added, or are removed.

The Spread Operator

  1. 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
  2. List 4 things that the spread operator can do.
    • Copying an array
    • Concatenating or combining arrays
    • Using Math functions
    • Using an array as arguments
  3. Give an example of using the spread operator to combine two arrays.
    • const arr3 = {...arr1,...arr2}
  4. Give an example of using the spread operator to add a new item to an array.
    • arr1 = [...arr1, newNumber]
  5. 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