The map() method in JavaScript creates a new array by calling a provided function on each element in the original array.
to loop through an array and display each value in JSX, you can use the map() method in conjunction with JSX.
key prop
key prop helps React identify each element in the virtual DOM, and improve performance when updating and rendering the component.
represented by three consecutive dots (…) and is used to spread or expand the elements of an iterable object (like an array or an object) into a new array or object.
Create a new array with elements from an existing array, Copy an existing array into a new array, Merge multiple objects into a new object, and then Pass an array or object as arguments to a function
const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; const combinedArray = […array1, …array2]; console.log(combinedArray); // [1, 2, 3, 4, 5, 6]
const originalArray = [1, 2, 3]; const newItem = 4; const newArray = […originalArray, newItem]; console.log(newArray); // [1, 2, 3, 4]
const object1 = { foo: ‘bar’, baz: 42 }; const object2 = { qux: true, quux: ‘hello’ }; const combinedObject = { …object1, …object2 }; console.log(combinedObject); // { foo: ‘bar’, baz: 42, qux: true, quux: ‘hello’ }
create the function wherever the state is that we are going to change
takes the current value of a “count” state variable, increments it by 1, and then sets the new value as the new state of the component.
defining the method in the parent component and passing it to the child component as a prop.
the child component can call the method as a function.