Advertisement
Guest User

Untitled

a guest
May 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface State {
  2.   companies?: Company[];
  3. }
  4.  
  5. type Props = RouteComponentProps<any>;
  6.  
  7. class Companies extends React.Component<Props, State> {
  8.   state = { companies: undefined }
  9.  
  10.   componentDidMount() {
  11.     fetch('/api/v1/company')
  12.       .then(data => data.json())
  13.       .then((companies:Company[]) => companies.sort((a,b) => a.symbol.localeCompare(b.symbol)))
  14.       .then(companies => {
  15.         this.setState({ companies })
  16.       })
  17.   }
  18.  
  19.   render() {
  20.     if (this.state.companies !== undefined) {
  21.       return (<div>
  22.         {this.state.companies!.map(company => (<CompanyListItem key={company.symbol} company={company}/>))}
  23.       </div>)
  24.     } else {
  25.       return 'loading'
  26.     }
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement