Created
March 15, 2019 11:14
-
-
Save erksch/933b4f60fe4a7b48637480c9e5d36a14 to your computer and use it in GitHub Desktop.
Orders component with delete order logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Orders.js | |
import React from 'react'; | |
import OrderService from './OrderService'; | |
class Orders { | |
constructor(props) { | |
super(props); | |
this.state = { | |
orders: [], | |
}; | |
} | |
async componentDidMount() { | |
const orders = await OrderService.list(); | |
this.setState({ orders }); | |
} | |
handleRemove = async (orderId) => { | |
await OrderService.delete(orderId); | |
this.setState(state => ({ | |
orders: state.orders | |
.filter(order => order.id !== orderId), | |
})); | |
}; | |
... | |
} | |
export default Orders; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment