Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addItem = event => {
- event.preventDefault();
- const {name, price} = this.state;
- const itemsInState = this.state.items;
- const itemsArrayLength = itemsInState.length;
- const id = itemsArrayLength
- ?
- (itemsInState[itemsArrayLength - 1].id + 1)
- :
- 1;
- this.setState({
- items: [
- ...itemsInState,
- Object.assign({}, {
- id,
- name,
- price
- })
- ],
- name: "",
- price: ""
- })
- };
Add Comment
Please, Sign In to add comment