Guest User

Untitled

a guest
Nov 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. class Creators extends React.Component {
  2.  
  3. constructor(props){
  4. super(props);
  5.  
  6. this.state = {
  7. comics: [],
  8. }
  9. };
  10.  
  11. byCreator = async (name) => {
  12. var names = name.split(" ");
  13. var firstName = names[0];
  14. var lastName = names[1];
  15. await fetch(`https://gateway.marvel.com:443/v1/public/creators?firstName=${firstName}%20&lastName=${lastName}&apikey=117b458635106b9721749634b53fb07b`)
  16. .then(res => res.json())
  17. .then(json => {
  18. const creatorID = json.data.results[0].id;
  19. return fetch(`https://gateway.marvel.com:443/v1/public/comics?creators=${creatorID}&apikey=117b458635106b9721749634b53fb07b`,
  20. { cache: "force-cache" })
  21. })
  22. .then(res => res.json())
  23. .then(d => this.setState({ comics: d.data.results }));
  24. }
  25.  
  26.  
  27. handleChange = (event) => {
  28. this.setState({ value: event.target.value });
  29. }
  30.  
  31. render () {
  32. return (
  33. <div>
  34. <div>
  35. <input
  36. type="search"
  37. placeholder="creator"
  38. value={this.state.value}
  39. onChange={this.handleChange}
  40. />
  41. <button onClick={this.byCreator}>Search</button>
  42. </div>
  43.  
  44. <ul>
  45. {this.state.comics.map(c =>
  46. <li key={c.id}>
  47. <p> {c.title} </p>
  48. <p> {c.description} </p>
  49. <img src={c.thumbnail.path + "." +c.thumbnail.extension}/>
  50. </li>
  51. )}
  52. </ul>
  53. </div>
  54.  
  55. )
  56. }
  57.  
  58.  
  59. }
Add Comment
Please, Sign In to add comment