Guest User

Untitled

a guest
Mar 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. class Weather extends Component {
  2. state = {
  3. title: [],
  4. body: [],
  5. id: [],
  6. userId: []
  7. }
  8. componentDidMount() {
  9. axios.get(`https://jsonplaceholder.typicode.com/posts`)
  10. .then(res => {
  11. const title = res.data;
  12. const body = res.data;
  13. const id = res.data;
  14. const userId = res.data;
  15. this.setState({ title:title, body: body, id:id, userId: userId });
  16. })
  17. }
  18.  
  19. render() {
  20. return (
  21. <div>
  22. <ul>
  23. {this.state.title.map(title => <li style={{listStyle: 'none'}}><strong>Title:</strong> {title.title}</li>)}
  24. </ul>
  25. <ul>
  26. {this.state.title.map((body) => <li style={{listStyle: 'none'}}><strong>Body:</strong> {body.body}</li>)}
  27. </ul>
  28. <ul>
  29. {this.state.title.map((id) => <li style={{listStyle: 'none'}}><strong>ID:</strong> {id.id}</li>)}
  30. </ul>
  31. <ul>
  32. {this.state.title.map((userId) => <li style={{listStyle: 'none'}}><strong>UserID:</strong> {userId.userId}</li>)}
  33. </ul>
Add Comment
Please, Sign In to add comment