- Lists and Keys
- The Spread Operator
- How to Pass Functions Between Components
- React Tutorial - Declaring a Winner
- React Docs - Lifting State Up
Why this topic matters as it relates to what I am studying in this module?
- What does .map() return?
.map() returns a new array
- If I want to loop through an array and display each value in JSX, how do I do that in React?
By using .map()
- Each list item needs a unique ____.
Element
- What is the purpose of a key?
A key is a special string attribute included when creating lists of elments. They help REACT identify which items have changed, are added, or are removed.
- What is the spread operator?
A useful and quick syntax for adding itmes to arrays, combining objects or arrays, and spreading an array out into a function's arguments.
-
List 4 things that the spread operator can do.
- Add items to arrays
- Combine objects/arrays
- Copying an array
- Adding to state in REACT
-
Give an example of using the spread operator to combine two arrays.
[...["😋😛😜🤪😝"]] // Array [ "😋😛😜🤪😝" ] [..."🙂🙃😉😊😇🥰😍🤩!"] // Array(9) [ "🙂", "🙃", "😉", "😊", "😇", "🥰", "😍", "🤩", "!" ]
const hello = {hello: "😋😛😜🤪😝"} const world = {world: "🙂🙃😉😊😇🥰😍🤩!"}
const helloWorld = {...hello,...world} console.log(helloWorld) // Object { hello: "😋😛😜🤪😝", world: "🙂🙃😉😊😇🥰😍🤩!" }
- Give an example of using the spread operator to add a new item to an array.
const fewFruit = ['🍏','🍊','🍌'] const fewMoreFruit = ['🍉', '🍍', ...fewFruit] console.log(fewMoreFruit) // Array(5) [ "🍉", "🍍", "🍏", "🍊", "🍌" ]
- 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() // 😂😂😂😂😂
- In the video, what is the first step that the developer does to pass functions between components?
Create the function wherever the state is that we are going to change
- In your own words, what does the increment function do?
It takes in a person object. Loops throught the array to find a matching person object. Then using .map(), generates a new array with the updated count increment.
- How can you pass a method from a parent component into a child component?
Just like you would any other prop, with dot notatation.
- How does the child component invoke a method that was passed to it from a parent component?
You could create a variable referencing the desired method, or you could simply use it in dot notation and pass it into the method being invoked.
- I would like to know more about passing functions between components. The video makes it seem rather simple, but until I can practice it, it seems challenging.