Passing Functions as Props
React Docs - lists and keys
- What does .map() return?
It returns a new array with a new values of manipulated inputs using a function inside the method.
- If I want to loop through an array and display each value in JSX, how do I do that in React?
First, we use the .map() method to render data then Parse and display data in an array of objects.
-
Each list item needs a unique Key
-
What is the purpose of a key?
Help React identify which items have changed, are added, or are removed.
The Spread Operator
- What is the spread operator?
The use of (โฆ) three dots to transform objects into arguments.
- List 4 things that the spread operator can do.
- Copying an array
- Using Math functions
- Adding an item to a list
- Combining objects
- Give an example of using the spread operator to combine two arrays.
const hello = {hello: โ๐๐๐๐คช๐โ}
const world = {world: โ๐๐๐๐๐๐ฅฐ๐๐คฉ!โ}
const helloWorld = {โฆhello,โฆworld}
- Give an example of using the spread operator to add a new item to an array.
const fruits = [โ๐โ,โ๐โ,โ๐โ,โ๐โ,โ๐โ]
const moreFruits = [โฆfruits];
fruits[0] = โ๐โ
- 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: โ๐โ}
How to Pass Functions Between Components
- In the video, what is the first step that the developer does to pass functions between components?
He set state outside to handle and pass the function to other components.
- In your own words, what does the increment function do?
It target the count value and update it every time you click on the button.
- How can you pass a method from a parent component into a child component?
Using props.
- How does the child component invoke a method that was passed to it from a parent component?
By passing it using a prop.
ย
ย
ย
ย ย
Get back to EMAMโS HOMEPAGE
I have created this page as a part of my project using Github, Please visit my profile, I will be more than happy to hear from you all. ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ยฉ Emam Shararah 2021