.map()
creates a new array populated with the results of running a callback function over every item in the arrayfunction renderNum() {
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li key={number.toString()}>
{number}
</li>
);
return (
<ul>{listItems}</ul>
);
}
key
...
Math
functionGive an example of using the spread operator to combine two arrays.
let numArr1 = [1,2,3];
let numArr2 = [4,5,6];
let numArr = [...numArr1,...numArr2]
Give an example of using the spread operator to add a new item to an array.
let names = ['tom', 'dick', 'harry'];
let moreNames = [...names, 'jane', 'janet'];
console.log(moreNames)//tom, dick, harry, jane, janet
Give an example of using the spread operator to combine two objects into one.
let hello = ['hello', 'world'];
let greet = ['what', 'a', 'beautiful', 'day'];
let phrase = [...hello,...greet] //hello world what a beautiful day
this.props.<functionName>
increment
function do?
count
property by 1 each time the Add
button is clicked by the userthis.props.<functionName>
this.props.<functionName>(this.props.<arg>)
to invoke the parent function using the corresponding parameter from the child component.map()
creates a new array populated with the results of running a callback function over every item in the arraykey
index
to serve as the key
...
this.props.<functionName>
heart
in App.js
App.js
state: heart
to Header.js
HornedBeast.js
componentsrender()
function in App.js
Header
component by adding hearts={this.state.hearts}
to the <Header>
component in App.js
Header.js
, reference the state via this.props.hearts
where ever you want to render the value of hearts
addHearts
method needs to be added to the <Header>
component in App.js
as well
<Header>
with {this.addHearts}
addHearts = () => {
this.setState({
hearts: this.state.hearts + '<heartImg>'
});
};
<Modal/>
to App.js
Modal
from Bootstrap into App.js
Will need two handle functions to open & close the modal
handleCloseModal = () => {
this.setState({
isModalShown: false
});
};
handleOpenModal= () => {
this.setState({
isModalShown: true
});
};
<Modal>
will take a show
and onHide
property that holds these functions:
<Modal show={this.state.isModalShown} onHide={this.handleCloseModal}>