a new array
we can use the .map() method
key
it let’s react know which elements it can safely refresh
...
, it expands an iterable array
- 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
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const combinedArray = [...array1, ...array2];
console.log(combinedArray); // Output: [1, 2, 3, 4, 5, 6]
const array = [1, 2, 3];
const newItem = 4;
const newArray = [...array, newItem];
console.log(newArray); // Output: [1, 2, 3, 4]
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
make sure that he’s operating at the top level
it takes in an object, and iterates a count value
pass it like you’d pass the other props.
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