Reading-Notes
code fellows 301
Read: 03 - Passing Functions as Props
Reading
React Docs - List and Keys
- .map() returns the values of an array as doubled values.
- To display values in an array in JSX, you can assign the array of elements to list items.
- Each list item needs a unique key.
- The purpose of a key is to help React identify which items have changed, are added, or are removed.
The Spread Operator
- The spread operator lets you add items to, combine, and spread out an array into a functionβs arguments.
- Spread operators can:
- Copying an array
- Concatenating or combining arrays
- Using Math functions
- Using an array as arguments
- How to combine two arrays:
const myArray = [`a`,`b`,`c`] const yourArray = [`d`,`e`,`f`] const ourArray = [...myArray,...yourArray] console.log(...ourArray) // a b c d e f - How to add a new item to an array:
const fewFruit = ['1','2','3'] const fewMoreFruit = ['x', 'y', ...fewFruit] console.log(fewMoreFruit) // Array(5) [ "x", "y", "1", "2", "3" ] - How 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
- He creates a function named, increment, that passes in a person.
-
The increment function updates the person objects.