Skip to the content.

Home Page

Class 03 Notes

React Docs - Lists and Keys

The map function returns an array. It can be an array of anything that was contained in the previous array that you used map on.

All you must do to display elements in JSX is to add {} around the variable containing the information.

Each list item needs a unique key. The purpose of such a key is to give the react element a stable identity.

The Spread Operator

The spread operator is â€Ķ, it is used to expands iterable objects into lists of arguements.

For example:


Math.max(1,3,5) // 5
Math.max([1,3,5]) // NaN
Math.max(...[1,3,5]) // 5

It can also be used for:

Example of combining arrays:


const myArray = [`ðŸĪŠ`,`ðŸŧ`,`🎌`]
const yourArray = [`🙂`,`ðŸĪ—`,`ðŸĪĐ`]
const ourArray = [...myArray,...yourArray]
console.log(...ourArray) // ðŸĪŠ ðŸŧ 🎌 🙂 ðŸĪ— ðŸĪĐ

Example of adding new items to an array:


const fewFruit = ['🍏','🍊','🍌']
const fewMoreFruit = ['🍉', '🍍', ...fewFruit]
console.log(fewMoreFruit) //  Array(5) [ "🍉", "🍍", "🍏", "🍊", "🍌" ]

Example of combining objects:


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 Funcitons Between Components

Things I want to know more about