Passing Functions as Props
Reading
What does .map()
return?
An array.
- If I want to loop through an array and display each value in JSX, how do I do that in React?
Using .map()
, we make every value in the array we are mapping go through html-like code we want it in.
- Each list item needs a unique __.
Key.
- What is the purpose of a key?
Keys help React identify which items have changed, are added, or are removed.
- What is the spread operator?
he spread syntax “spreads” the array into separate arguments.
-
List 4 things that the spread operator can do.
- Copying an array
- Concatenating or combining arrays
- Using Math functions
- Using an array as arguments
- Give an example of using the spread operator to combine two arrays.
const hello = ['hello']
const world = ['world']
const helloWorld = [...hello,...world]
console.log(...helloWorld) // hello world
- Give an example of using the spread operator to add a new item to an array.
const fruit1 = ['apple', 'pineapple', 'banana']
const fruit2 = ['orange']
const fruits = [...fruit1,...fruit2]
console.log(...fruits) // apple pineapple banana orange
- Give an example of using the spread operator to combine two objects into one.
const hello = {hello: “hayoo”} const world = {world: “globe”}
const helloWorld = {…hello,…world} console.log(helloWorld) // Object { hello: “hayoo”, world: “globe” }
Videos
- In the video, what is the first step that the developer does to pass functions between components?
make a constructor.
- In your own words, what does the increment function do?
Increase the number besides the names the instructor used.
- How can you pass a method from a parent component into a child component?
By passing it as an attribute through the html-like code (example: increment={this.increment}
).
- How does the child component invoke a method that was passed to it from a parent component?
You can call it through this.props.increment()
.
301 | Home |
---|---|
read01 | Introduction to React and Components |
read02 | State and Props |
read03 | Passing Functions as Props |
read04 | React and Forms |
read05 | Putting it all together |
read06 | NODE.JS |
read07 | REST |
read08 | APIs |
read09 | FUNCTIONAL PROGRAMMING |
read10 | In memory storage |
read11 | Authentication |
read12 | Mongo and Mongoose |
read13 | CRUD |
read14 | Project Ideas |
read15 | Project Kickoff |