Skip to the content.

Code 301 Class 03 Reading Notes

React Docs - lists and keys

  1. What does .map() return? creates a new array populated with elements from the provided function on every element in the calling array.
  2. If I want to loop through an array and display each value in JSX, how do I do that in React? By transforming arrays into lists of elements, using .map() to loop through an array.
  3. Each list item needs a unique key or string.
  4. What is the purpose of a key? Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.

The Spread Operator

  1. What is the spread operator? The spread operator is an ellipsis of three dots (...) to expand an iterable object into the list of arguments.
  2. List 4 things that the spread operator can do.
  1. Give an example of using the spread operator to combine two arrays. let merged = [...arr1, ...arr2];
  2. Give an example of using the spread operator to add a new item to an array. let addMore = [1, 2, ...manyMore];
  3. Give an example of using the spread operator to combine two objects into one. let totalObject = {...recallObj, ...recollectionObj};

How to Pass Functions Between Components

  1. First step that the developer does to pass functions between components? Create a function where you will call and pass in a object with map.
  2. What does the increment function do? Looping through the people array, and checking if there is a match in the name, if there is a match, the count will increase by one.
  3. How can you pass a method from a parent component into a child component? Pass it with a prop, by creating something into the child component
  4. How does the child component invoke a method that was passed to it from a parent component? Call the parent method using props

Things I want to know more about

<—BACK