import React from 'react'
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
data: []
}
this.genData = this.genData.bind(this)
}
genData() {
this.setState(currentData => ({
...currentData,
data: [
...currentData.data,
...Array
.from({ length: 10 }, (_, id) =>
({
id: id + this.state.data.length,
value: Math.random() * 100
})
)
]
}))
}
componentDidMount() {
this.genData()
}
render() {
return <React.Fragment>
{this.state.data.map(({ id, value }) => <div key={id}>{value}</div>)}
<button onClick={this.genData}>load more</button>
</React.Fragment>
}
}
export default App