The .map() method is a function that operates on an array and returns a new array with the same number of items. It applies a callback function to each element of the original array and uses the return value of the callback function to create the corresponding element of the new array.
Use the .map() method along with JSX to create a new array of React elements.
Each list item in React needs a unique “key” prop.
The purpose of a “key” prop in React is to help React efficiently update the user interface when the data changes. When a list of items is rendered in React, React uses the “key” prop to keep track of which items have been added, removed, or modified.
The spread operator is a syntax that allows an iterable such as an array or an object expression to be expanded or “spread” into multiple elements. It is used with three consecutive dots ….
Copying an array, concatenating or combining arrays, using Math functions, using an array as arguments
` const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combined = […arr1, …arr2];`
const oldArr = [1, 2, 3];
const newItem = 4;
const newArr = [...oldArr, newItem];
const person = { name: 'John', age: 30 };
const address = { street: '123 Main St', city: 'Anytown', state: 'CA' };
const contactInfo = { ...person, ...address };
First he created the functions wherever the state is that we’re going to change
When the increment function is called, it adds a determined value to the current value of the variable, thereby incrementing the variable
Use the props method by following the below:
Define the method you want to pass down from the parent component.
Pass the method as a prop to the child component.
In the child component, access the method through props and use it as needed.
A child component can invoke the method by calling it as a function. The method is typically passed down to the child component as a prop, and the child component can access it through this.props.
Sources