it returns a new array with element passed through it (same or modified one)
example from source:
function NumberList(props) { const numbers = props.numbers; const listItems = numbers.map((number) => <li>{number}</li> ); return ( <ul>{listItems}</ul> ); }
const numbers = [1, 2, 3, 4, 5]; ReactDOM.render( <NumberList numbers={numbers} />, document.getElementById('root') );
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.
InJavaScript, spread syntax refers to the use of an ellipsis of three dots (β¦) to expand an iterable object into the list of arguments.
const array1 = [
a,
b,
c] const array2 = [
d,
e,
f] const outArray = [...array1,...array2] console.log(...outArray) // a b c d e f
const arr = ['a', 'b', 'c', 'd', 'e', 'f'] const outArray2 = [...arr, 'g', 'h', 'i'] console.log(outArray2) // ["a", "b", "c", "d", "e", "f", "g", "h", "i"] ... also I can add elements at start of an array
example from source:
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() // πππππ
make an object and create a method (function) so we can map or loop through and can access its value by props, and can use state.
this is a function used to update (increase) the value whenever called⦠usually use counter increased by clicking
we can access it by dot notation one by one or looping⦠then pass it from parent to child by props.
Answer that I found by search in the internet: Create a boolean variable in the state in the parent class. Update this when you want to call a function. Create a prop variable and assign the boolean variable. From the child component access that variable using props and execute the method you want by having an if condition.
I am excited to learn more about this topics and learn by practice.