reading-notes

Readings: Passing Functions as Props

Reading

React Docs - Lists & Keys

  1. .map() returns a new array with the same number of items as the original array, but with each item transformed by a callback function.
  2. Use .map() to loop through an array and display each value in JSX in React.
  3. Each list item needs a unique “key”.
  4. The purpose of a key in React is to help identify each item in the list, so that React can efficiently update and re-render the list when it changes.

The Spread Operator

  1. What is the spread operator?
    • useful and quick syntax for adding items to arrays, combining arrays or objects, and spreading an array out into a functions arguments.
  2. List 4 things that the spread operator can do.
    • concatenate arrays
    • copy arrays
    • add items to an array
    • merge objects
  3. Give an example of using the spread operator to combine two arrays.
    • […[this is an array]] and […“this is a different array] and now they are combined
  4. Give an example of using the spread operator to add a new item to an array.
    • const arr = [1, 2, 3]; const arr1 = [4, 5, 6]; Output: [1, 2, 3, 4]
  5. Give an example of using the spread operator to combine two objects into one.
    • const helloWorld = {...hello,...world}

How to Pass Functions Between Components

  1. In the video, what is the first step that the developer does to pass functions between components?
  2. In your own words, what does the increment function do?
    • increases the count on a specific condition (a matched object or whatever)
  3. How can you pass a method from a parent component into a child component?
  4. How does the child component invoke a method that was passed to it from a parent component?

    I don’t know. I’m tired and going to bed.