Reading 301-03
Readings: Passing Functions as Props
React Docs - lists and keys
1.What does .map() return?
- A new array
- If I want to loop through an array and display each value in JSX, how do I do that in React?
- const numbers = [1, 2, 3, 4, 5]; const listItems = numbers.map((number) =>
);
-
Each list item needs a unique __.
- What is the purpose of a key?
- A special string attribute you need to include when creating lists
- Helpd id whcic items have changed, added, or removed
The Spread Operator
- What is the spread operator?
- Spreads the array into sep arguments
- List 4 things that the spread operator can do.
- use math functions
- combine objects
- Adding to state in React
- copying an array
-
Give an example of using the spread operator to combine two arrays.
const myArray = [
π€ͺ
,π»
,π
] const yourArray = [π
,π€
,π€©
] const ourArray = [β¦myArray,β¦yourArray] console.log(β¦ourArray) // π€ͺ π» π π π€ π€© - Give an example of using the spread operator to add a new item to an array.
- const fruits = [βπβ,βπβ,βπβ,βπβ,βπβ] const moreFruits = [β¦fruits]; console.log(moreFruits) // Array(5) [ βπβ, βπβ, βπβ, βπβ, βπβ ] fruits[0] = βπβ console.log(β¦[β¦fruits,ββ¦β,β¦moreFruits]) // π π π π π β¦ π π π π π
- Give an example of using the spread operator to combine two objects into one.
- 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() // πππππ
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?
- How does the child component invoke a method that was passed to it from a parent component?
Things I want to learn more about
- Web Dev Simplified (YouTube) Medium.com reactjs.org