-
What does .map() return?
-
If I want to loop through an array and display each value in JSX, how do I do that in React?
we loop through the numbers array using the JavaScript map() function. and render it to the DOM
- Each list item needs a unique ____. key
- What is the purpose of a key? Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.
You can build collections of elements and include them in JSX using curly braces {}.
Usually you would render lists inside a component.
We can refactor the previous example into a component that accepts an array of numbers and outputs a list of elements.
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.
When ...arr is used in the function call, it ‘expands’ an iterable object arr into the list of arguments.
“Spread operator to the rescue! It looks similar to rest parameters, also using ..., but does quite the opposite.
The … spread operator is useful for many different routine tasks in JavaScript, including the following:
-
Copying an array : Using the … spread operator is a convenient way to copy an array or combine arrays, and it can even add new items.
-
Concatenating or combining arrays
-
Using Math functions
-
Using an array as arguments : ince the spread operator “spreads” an array into different arguments, any functions that accepts multiple any number of arguments can benefit from use of the spread operator.
-
Adding an item to a list
-
Adding to state in React
-
Combining objects
-
Converting NodeList to an array