Reading 301-03

Readings: Passing Functions as Props

React Docs - lists and keys

1.What does .map() return?

  • A new array
  1. If I want to loop through an array and display each value in JSX, how do I do that in React?
    • const numbers = [1, 2, 3, 4, 5]; const listItems = numbers.map((number) =>
  • {number}
  • );

    1. Each list item needs a unique __.

    2. What is the purpose of a key?
      • A special string attribute you need to include when creating lists
      • Helpd id whcic items have changed, added, or removed

    The Spread Operator

    1. What is the spread operator?
      • Spreads the array into sep arguments
    2. List 4 things that the spread operator can do.
      • use math functions
      • combine objects
      • Adding to state in React
      • copying an array
    3. Give an example of using the spread operator to combine two arrays.

      const myArray = [πŸ€ͺ,🐻,🎌] const yourArray = [πŸ™‚,πŸ€—,🀩] const ourArray = […myArray,…yourArray] console.log(…ourArray) // πŸ€ͺ 🐻 🎌 πŸ™‚ πŸ€— 🀩

    4. Give an example of using the spread operator to add a new item to an array.
      • const fruits = [β€˜πŸβ€™,β€™πŸŠβ€™,β€™πŸŒβ€™,β€™πŸ‰β€™,β€™πŸβ€™] const moreFruits = […fruits]; console.log(moreFruits) // Array(5) [ β€œπŸβ€, β€œπŸŠβ€, β€œπŸŒβ€, β€œπŸ‰β€, β€œπŸβ€ ] fruits[0] = β€˜πŸ‘β€™ console.log(…[…fruits,β€™β€¦β€˜,…moreFruits]) // πŸ‘ 🍊 🍌 πŸ‰ 🍍 … 🍏 🍊 🍌 πŸ‰ 🍍
    5. Give an example of using the spread operator to combine two objects into one.
      • const objectOne = {hello: β€œπŸ€ͺ”} const objectTwo = {world: β€œπŸ»β€} const objectThree = {…objectOne, …objectTwo, laugh: β€œπŸ˜‚β€} console.log(objectThree) // Object { hello: β€œπŸ€ͺ”, world: β€œπŸ»β€, laugh: β€œπŸ˜‚β€ } const objectFour = {…objectOne, …objectTwo, laugh: () => {console.log(β€œπŸ˜‚β€.repeat(5))}} objectFour.laugh() // πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚

    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?

    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?

    Things I want to learn more about

    1. Web Dev Simplified (YouTube) Medium.com reactjs.org