Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. handleAddToList = () => {
  2. let items = [...this.state.items];
  3. let lastId = Math.max.apply(null, items.id);
  4. let newId = lastId + 1;
  5.  
  6. items.filter(i => i.title == this.state.text).length === 1
  7. ? alert("This item is on the list already.")
  8. : items.push({
  9. id: newId,
  10. title: this.state.text,
  11. found: 0,
  12. value: 0,
  13. icon: "delete"
  14. });
  15. this.setState({ items: items });
  16. };
  17.  
  18. <Input
  19. placeholder="Start typing"
  20. label={"Your next shop list item..."}
  21. onChangeText={text => this.setState({ text })}
  22. />
  23. <Button title="Add to list" onPress={() => this.handleAddToList()} />
  24.  
  25. Warning: Encountered with two children with the same key, '"-infinity"'.
  26.  
  27. <ListItem
  28. key={l.id}
  29. title={l.title}
  30. rightIcon={{ name: l.icon, color: "#cc0033" }}
  31. bottomDivider={true}
  32. />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement