ReadingNotes

Passing Functions as Props

List and keys

Questions for list and keys

  1. map returns a new array with the same number of elements as the original array, but with each element transformed according to the function provided to .map().
  2. To loop through an array and display each value in JSX, you can use the map() method of the array in your React component’s render() method.
  3. Key prop
  4. the key prop is used to identify a specific element in a list of similar elements.

The Spread operator

Questions for spread operator

  1. The spread operator (…) is a feature in JavaScript that allows an iterable to be expanded or spread into multiple elements or properties. In the case of arrays, the spread operator can be used to create a new array that contains the elements of an existing array, along with additional elements.
  2. Expand arrays, Concatenate arrays, Copy objects, and Merge objects is what the spread operator can do.
  3. Combining 2 arrays: const array1 = [1, 2, 3]; const array2 = [4, 5, 6];

const combinedArray = […array1, …array2];

console.log(combinedArray); // [1, 2, 3, 4, 5, 6]

  1. Adding a new item to an array: const myArray = [1, 2, 3];

const newArray = […myArray, 4];

console.log(newArray); // [1, 2, 3, 4]

  1. combining 2 objects into one: const object1 = { name: ‘John’, age: 30 }; const object2 = { city: ‘New York’, country: ‘USA’ };

const combinedObject = { …object1, …object2 };

console.log(combinedObject); // { name: ‘John’, age: 30, city: ‘New York’, country: ‘USA’ }

how to pass funcitons between components

  1. The increment function is used to increase the count value in the state by one every time it is called. It takes the current state value as an argument, and then returns a new state object with the count value increased by one.
  2. The increment function is used to increase the count value in the state by one every time it is called.
  3. To pass a method from a parent component to a child component, you can do the following: Define the method in the parent component. Pass the method as a prop to the child component. In the child component, use the prop to invoke the method.
  4. To invoke a method that was passed to a child component from a parent component, the child component needs to call the method using the prop that was passed to it.

things i want to know more about

I want to know more about how to know when to use the map function