Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import axios from "axios";
  3. import styles from './App.css';
  4.  
  5. import Header from './Components/Header/Header';
  6. import GifList from './Components/GifList/GifList';
  7. import SearchBar from './Components/SearchBar/SearchBar'
  8.  
  9.  
  10. class App extends Component {
  11.  
  12. state = {
  13. title: "Giphy Search App",
  14. gifs: [],
  15. userInput: "duke"
  16. }
  17.  
  18. componentDidMount() {
  19. axios.get(`http://api.giphy.com/v1/gifs/search?q=${this.state.userInput}&limit=20&api_key=ms344CewNH5NEbybHwQifMZImoQfEQ38`)
  20. .then((res) => {
  21. const arr = res.data.data;
  22. this.setState({ gifs: arr });
  23. });
  24. }
  25.  
  26. searchQuery = () => {
  27. this.setState({ userInput: "unc" });
  28. }
  29.  
  30. render() {
  31. return (
  32. <div className={styles.app}>
  33. <Header title={this.state.title}/>
  34. <SearchBar query={this.searchQuery}/>
  35. {this.state.gifs.length > 0 && <GifList gifList={this.state.gifs}/>}
  36. </div>
  37. );
  38. }
  39. }
  40.  
  41. export default App
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement