Notes 2
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?
- map()
Each list item needs a unique __.
- Values
What is the purpose of a key?
- they indicate if something has been changed or edited in the code
What is the spread operator?
- it allows you to expand objects or strings into elements
List 4 things that the spread operator can do.
- Copying an array
- Using Math functions
- Adding to state in React
- Converting NodeList to an array
Give an example of using the spread operator to combine two arrays.
- Math.min and math.max both return numbers within a range
Give an example of using the spread operator to add a new item to an array.
(example added from https://medium.com/coding-at-dawn/how-to-use-the-spread-operator-in-javascript-b9e4a8b06fab)
- const fewFruit = [βπβ,βπβ,βπβ]
const fewMoreFruit = [βπβ, βπβ, β¦fewFruit]
console.log(fewMoreFruit) // Array(5) [ βπβ, βπβ, βπβ, βπβ, βπβ ]
Give an example of using the spread operator to combine two objects into one.
(example added from https://medium.com/coding-at-dawn/how-to-use-the-spread-operator-in-javascript-b9e4a8b06fab)
- const objectOne = {hello: βπ€ͺβ}
const objectTwo = {world: βπ»β}
const objectThree = {β¦objectOne, β¦objectTwo, laugh: βπβ}
console.log(objectThree) // Object { hello: βπ€ͺβ, world: βπ»β, laugh: βπβ }
const objectFour = {β¦objectOne, β¦objectTwo, laugh: () => {console.log(βπβ.repeat(5))}}
objectFour.laugh() // πππππ
In the video, what is the first step that the developer does to pass functions between components?
- you must create a function in the state you would like it operate in
In your own words, what does the increment function do?
- they pull individual sections of arrays to list specific parts
How can you pass a method from a parent component into a child component?
How does the child component invoke a method that was passed to it from a parent component?
BACK TO HOME