Here we will use map
to iterate over the elements of an array and produce a list, or actually, creat a component that renders a list with multiple elements, something similar to this:
In order to be able to render multiple HTML elements (like li
s of ol
or ul
), loops will serve as a handy tool, the steps needed to complete the component are as follows:
map
).map
will be li
with needed data.ul
.Keys help React trace changes of an item, id and index can be used as keys, make sure where to define a key and make it unique, you can see example for where and where not to use keys and how to ensure it is unique here;
...
The spread operator is a useful and quick syntax for adding items to arrays, combining arrays or objects, and spreading an array out into a function’s arguments.
- Dr. Derek Austin
Spread operators can be used for:
Copying an array
Concatenating arrays
Using Math functions
And many other uses, you can visit medium for more information.
To pass fucntions between components follow the following steps:
Define the function in parent component.
Pass the function as aprop to the child component.
In our video a function called increment was used to add 1 to the count when a button is clicked.