reading-note

Passing Functions as Props

1-We use the array.map() to store new modified elements to a new array in order to use it for a different purpose.

2-To loop through an array and display each value we use the map() method within the inline curly brackets of JSX. An example of that using function based components:

function NumberList(props) {
  const numbers = props.numbers;
  const listItems = numbers.map((number) => <li>{number}</li>);

  return <ul>{listItems}</ul>;
}

const numbers = [1, 2, 3, 4, 5];
ReactDOM.render(
  <NumberList numbers={numbers} />,
  document.getElementById("root")
);

3-Each list item in ReactJs needs a unique key, which is an attribute that cant be passed as props to the child components and its value is usually a string.

4-The purpose of the keys is to give the list items a stable identity and to help React identifying which items have changed, added or removed.

The Spread Operator

Things that the spread operator can do :

Passing Functions Between Components