reading notes for code fellows
This is all important when we are just learning how to use props and pass things between children and parents, because reading about it and doing it in class helps to cement the fact that we need to remember to add keys and how to move things from place to place to make them accessible.
you can use {} to build a collection of elements and include them in JSX. EX
let arr = [1,2,3]
let newArr = arr.map(num => <li>{num}</li>);
and then you can place the array of items into a list using <ul>{newArr}</ul>. Usually this would be rendered within a component.
Keys help React keep track of what has been changed, added and removed, and should be given to the elements within our previous array for them to have a stable identity. The best way to assign a key is to use idx or id, which grabs the index of the element, or an ID from your data, respectively, though it is far better to use an ID, as if the order of items in the array changes it could cause issues. When you assign a key, it only matters in the context of the surrounding array, so it should be on the component rather than on the list item itself. Keys also only need to be unique among siblings, so they can be reused under different parents. Keys also are not passed in to your component as props, so if you need the value from a key, it needs to be passed explicitly as props with a different name.
Spread syntax refers to an ellipsis ... used to expand an iterable object into a list of arguments. When you are trying to give an array to something expecting separate numbers, ex (1,2,3) you can pass in (...[1,2,3]) to get around the requirement. The spread operator works on any iterable object, including strings, and can be used to
A benefit of using the spread operator is that it copies by reference, leaving the original array alone, and meaning changes to the original array will not affect the copy as long as the changes are on a shallow level.
newArr = [...arr1, ...arr2]arr2 = [...arr1, 4]newObj = {...obj1, ...obj2}