reading-notes

These are my reading notes for Code Fellows


Project maintained by taegorov Hosted on GitHub Pages — Theme by mattgraham

Home

Reading Notes Code 301: Day 3

Note: As with day 2, I accidentally read all of the Intro to React page for Read 01. My notes for that particular reading can be found in the day 1 reading here.

Lifting States Up

A couple examples of these changes, as discussed in the reading:

The inputs stay in sync because their values are computed from the same state (source)


Lists and Keys

const exampleNumbers = [2, 4, 6, 8, 10];
const showItems = exampleNumbers.map((exampleNumbers) =>
  <li>{exampleNumbers}</li>
);

ReactDOM.render(
  <ul>{showItems}</ul>,
  document.getElementById('root')
);

The above code displays the following (although it omits the highly-suggested key. Key’s give elements a “stable identity”):

- 2
- 4
- 6
- 8
- 10

A[nother] good rule of thumb is that elements inside the map() call need keys.

(source)


The Spread Operator

The spread operator is a useful and quick syntax for adding items to arrays, combining arrays or objects, and spreading an array out into a function’s arguments.

(source)

Trying to find the largest number in an array like this:

Math.max([2,8,55])

Would result in “NaN”. Using a spread operator like this:

Math.max(...[2,8,55])

Would correctly produce “55”!

const fruits = ['🍏','🍊','🍌','🍉','🍍']
const moreFruits = [...fruits];
console.log(moreFruits) // Array(5) [ "🍏", "🍊", "🍌", "🍉", "🍍" ]
fruits[0] = '🍑'
console.log(...[...fruits,'...',...moreFruits]) //  🍑 🍊 🍌 🍉 🍍 ... 🍏 🍊 🍌 🍉 🍍