- What does .map() return?
a new array
- If I want to loop through an array and display each value in JSX, how do I do that in React?
we can use the .map() method
- Each list item needs a unique ____.
key
- What is the purpose of a key?
it let's react know which elements it can safely refresh
- What is the spread operator?
...
, it expands an iterable array
- List 4 things that the spread operator can do.
- a copy of an array/onject
- concatenate arrays or objects
- spread elements of an array/object in another arr/obj
- pass elements of an arr/obj as args to a function
- Give an example of using the spread operator to combine two arrays.
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const combinedArray = [...array1, ...array2];
console.log(combinedArray); // Output: [1, 2, 3, 4, 5, 6]
- Give an example of using the spread operator to add a new item to an array.
const array = [1, 2, 3];
const newItem = 4;
const newArray = [...array, newItem];
console.log(newArray); // Output: [1, 2, 3, 4]
- Give an example of using the spread operator to combine two objects into one.
const object1 = { name: 'John', age: 30 };
const object2 = { city: 'New York', country: 'USA' };
const combinedObject = { ...object1, ...object2 };
console.log(combinedObject); // Output: { name: 'John', age: 30, city: 'New York', country: 'USA' }
How to Pass Functions Between Components
- In the video, what is the first step that the developer does to pass functions between components?
make sure that he's operating at the top level
- In your own words, what does the increment function do?
it takes in an object, and iterates a count value
- How can you pass a method from a parent component into a child component?
pass it like you'd pass the other props.
- How does the child component invoke a method that was passed to it from a parent component?
in the video he passes
{this.increment}
, and then it's called from the child component as{this.props.increment()}
.
React Tutorial through ‘Declaring a Winner’ React Docs - Lifting State Up
- Google Bard and ChatGPT