22
loading...
This website collects cookies to deliver better user experience
state = {
sorted: false
}
<button onClick={() => this.setState({sorted: !this.state.sorted})}>Click to Sort</button>
{this.state.sorted ? sortedTransactions.map(t => <TransactionCard key={t.id} {...t} /> ) : this.props.transactions.map(t => <TransactionCard key={t.id} {...t} /> )}
const sortedTransactions = [...this.props.transactions].sort((a, b) => (a.amount - b.amount))