Advertisement
Guest User

ksd

a guest
Jul 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { ItemRestClient } from './ItemRestClient';
  3. import styled from 'styled-components';
  4. import Loading from '../core/Loading';
  5. import ErrorInfo from '../core/ErrorInfo';
  6.  
  7.  
  8.  
  9. // Create a <Title> react component that renders an <h1> which is
  10. // centered, palevioletred and sized at 1.5em
  11. const ItemListContainer = styled.div`
  12.  
  13. text-align: center;
  14.  
  15. `;
  16.  
  17. const itemRestClient = new ItemRestClient();
  18.  
  19. class ItemList extends Component {
  20. constructor(props){
  21. super(props);
  22. this.state = { items: null, error: null }
  23. console.log("IL - constructor");
  24. }
  25.  
  26. componentDidMount(){
  27. itemRestClient.search({})
  28. .then((items) => this.setState({ items }))
  29. .catch((error) => this.setState({ error }));
  30. console.log("IL - componentDidMount");
  31. }
  32. render() {
  33. console.log("IL - render");
  34. const { items, error } = this.state;
  35. if (error){
  36. return <ErrorInfo error={error}/>
  37. }
  38. if (!items){
  39. return <Loading/>
  40. }
  41. return (
  42. <ItemListContainer>
  43. {JSON.stringify(items)}
  44. </ItemListContainer>
  45.  
  46. );
  47. }
  48. }
  49.  
  50. export default ItemList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement