My reading journal for Code Fellows.
The map function returns a new array that contains each item from the previous array, usually after you’ve performed some operation on them.
Loop through the array with your function of choice and return a new array where you’ve converted the values to your desired element type. You can now put the new array in the element where you want it to display, just make sure you wrap the variable name in curly braces so that it is interpreted correctly.
When creating list a list of elements, each item needs to have a unique key attribute.
Keys allow React to monitor changes to items because the key value uniquely identifies each element.
The spread operator is a syntax that allows you to expand iterable objects into lists of arguments.
Spread can copy an array, combine arrays, combine objects, and add to state in React.
Spread can combine arrays like this:
let arr1 = [1,2,3];
let arr2 = [4,5,6];
let addArr = [...arr1,...arr2];
This example combines the two arrays into one where the new contents is [1,2,3,4,5,6]
.
let nums = [1,2,3];
let moreNums = [...nums,4,5];
//moreNums is now [1,2,3,4,5]
This easily adds an array and new items to a new array.
let obj1 = {test: 1}
let obj2 = {example: 2}
let obj3 = {...obj1,...obj2}
//obj3 now contains{test: 1, example: 2}
Similar to the other combining functionality of spread, you can easily add two objects together like this.
Create a function at the same level as the state you want to change.
The increment function uses conditional logic to find the desired object in an array of objects, update its count, and then update the state of the array to reflect the new count.
A method can be passed from parent to child through the use of props.
A child component can invoke a passed method by calling it with this.props.methodName()
.
I want to get practice using Spread. I think it is a really cool tool from the reading and it seems like it will provide a bunch of utility. I’m looking forward to getting better at incorporating tools like this into my code.