Guest User

Untitled

a guest
May 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. addItem = event => {
  2. event.preventDefault();
  3. const {name, price} = this.state;
  4. const itemsInState = this.state.items;
  5. const itemsArrayLength = itemsInState.length;
  6. const id = itemsArrayLength
  7. ?
  8. (itemsInState[itemsArrayLength - 1].id + 1)
  9. :
  10. 1;
  11. this.setState({
  12. items: [
  13. ...itemsInState,
  14. Object.assign({}, {
  15. id,
  16. name,
  17. price
  18. })
  19. ],
  20. name: "",
  21. price: ""
  22. })
  23. };
Add Comment
Please, Sign In to add comment