reading-notes


Project maintained by Razan-am Hosted on GitHub Pages — Theme by mattgraham

React Docs - lists and keys

What does .map() return?

Example:

const numbers = [1, 2, 3, 4, 5];

const doubled = numbers.map((number) => number * 2);

console.log(doubled);

In the example above we use the map() function to take an array of numbers and double their values. We assign the new array returned by map() to the variable doubled and log it.


If I want to loop through an array and display each value iSX, how do I do that in React?

Example:

const numbers = [1, 2, 3, 4, 5];

const listItems = numbers.map((number) =>

<li>{number}</li>

);

Below, we loop through the numbers array using the map() function. We return a <li> element for each item. Finally, we assign the resulting array of elements to listItems.


Each list item needs a unique ____.

Example:

const numbers = [1, 2, 3, 4, 5];

const listItems = numbers.map((number) =>

<li key={number.toString()}>

{number}

</li>

);


What is the purpose of a key?

===================================================

The Spread Operator

What is the spread operator?

When …arr is used in the function call, it expands an iterable object arr into the list of arguments.

List 4 things that the spread operator can do.

Give an example of using the spread operator to combine two arrays.

Give an example of using the spread operator to add a new item to an array.

Give an example of using the spread operator to combine two objects into one.

## How to Pass Functions Between Components

### In the video, what is the first step that the developer does to pass functions between components?

In your own words, what does the increment function do?.

How can you pass a method from a parent component into a child component?

As in the video this.props.increament(this.props.name);

and in the parent component we pass it as any other props by name and the value that refrence to the funtion we created to change the state of the objects.

As in the video increament={this.increament};

How does the child component invoke a method that was passed to it from a parent component?

References:

@React/React Docs - lists and keys

@Dr. Derek Austin/How to Use the Spread Operator (…) in JavaScript

@Steve Griffith - Prof3ssorSt3v3/How to Pass Functions Between Components