@abouthalf/

RemoteDataWithReact

React

No description

fork
loading
Files
  • src
    • App.js
    • App.css
    • index.css
    • index.js
    • logo.svg
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.2384645506350076","path":"src/App.js","file":{"path":"src/App.js","content":{"asEncoding":{"base64":"aW1wb3J0IFJlYWN0LCB7IENvbXBvbmVudCB9IGZyb20gJ3JlYWN0JzsKaW1wb3J0ICcuL0FwcC5jc3MnOwoKY2xhc3MgQXBwIGV4dGVuZHMgQ29tcG9uZW50IHsKCiAgc3RhdGUgPSB7CiAgICBwaG90b3M6IFtdCiAgfQoKICBjb21wb25lbnREaWRNb3VudCgpIHsKICAgIGZldGNoKCJodHRwczovL2pzb25wbGFjZWhvbGRlci50eXBpY29kZS5jb20vcGhvdG9zIikKICAgICAgLnRoZW4ocmVzID0+IHJlcy5qc29uKCkpCiAgICAgIC50aGVuKHBob3RvcyA9PiB7CiAgICAgICAgcGhvdG9zID0gcGhvdG9zLnNsaWNlKDAsOSk7CiAgICAgICAgdGhpcy5zZXRTdGF0ZSh7IHBob3RvcyB9KTsKICAgICAgfSkKICAgICAgLmNhdGNoKGVyciA9PiB7CiAgICAgICAgdGhpcy5zZXRTdGF0ZSh7IHBob3RvczogW10gfSk7CiAgICAgIH0pCiAgfQoKICByZW5kZXJQaG90byh7IHRpdGxlLCB0aHVtYm5haWxVcmwsIHVybCB9KSB7CiAgICByZXR1cm4gPGxpPgogICAgICA8YSBocmVmPXt1cmx9PgogICAgICAgIDxpbWcgc3JjPXt0aHVtYm5haWxVcmx9IGFsdD17dGl0bGV9IC8+CiAgICAgIDwvYT4KICAgIDwvbGk+CiAgfQoKICByZW5kZXIoKSB7CiAgICBjb25zdCB7IHBob3RvcyB9ID0gdGhpcy5zdGF0ZTsKICAgIHJldHVybiAoCiAgICAgIDxkaXYgY2xhc3NOYW1lPSJBcHAiPgogICAgICAgIDx1bD4KICAgICAgICAgIHtwaG90b3MubWFwKHAgPT4gdGhpcy5yZW5kZXJQaG90byhwKSl9CiAgICAgICAgPC91bD4KICAgICAgPC9kaXY+CiAgICApOwogIH0KfQoKZXhwb3J0IGRlZmF1bHQgQXBwOwo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { Component } from 'react';
import './App.css';

class App extends Component {

  state = {
    photos: []
  }

  componentDidMount() {
    fetch("https://jsonplaceholder.typicode.com/photos")
      .then(res => res.json())
      .then(photos => {
        photos = photos.slice(0,9);
        this.setState({ photos });
      })
      .catch(err => {
        this.setState({ photos: [] });
      })
  }

  renderPhoto({ title, thumbnailUrl, url }) {
    return <li>
      <a href={url}>
        <img src={thumbnailUrl} alt={title} />
      </a>
    </li>
  }

  render() {
    const { photos } = this.state;
    return (
      <div className="App">
        <ul>
          {photos.map(p => this.renderPhoto(p))}
        </ul>
      </div>
    );
  }
}

export default App;