Guest User

Untitled

a guest
Jan 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. this.setState({ items: items, itemDetail: items[0], value: this.state.value })
  2.  
  3. constructor(props){
  4. super(props);
  5. this.state = {
  6. items: []
  7. }
  8. this.handleChange = this.handleChange.bind(this);
  9. }
  10.  
  11. handleChange(event) {
  12. this.setState({ value: event.target.value });
  13. }
  14.  
  15. componentDidMount(){
  16. const items = [
  17. {
  18. 'id': 0,
  19. 'name': 'firstName'
  20. },
  21. {
  22. 'id': 1,
  23. 'name': 'secondName'
  24. }
  25. ];
  26.  
  27. this.setState({ items: items, itemDetail: items[0] });
  28. }
  29.  
  30.  
  31. render(){
  32.  
  33. const { items, itemDetail } = this.state;
  34.  
  35. console.log(itemDetail);
  36.  
  37. return(
  38. <div className="container">
  39. {itemDetail}
  40. </div>
  41. );
  42. }
Add Comment
Please, Sign In to add comment