Advertisement
cesarnascimento

Untitled

Apr 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import axios from "axios";
  3. import Navbar from "./components/Navbar";
  4. import Modal from "react-modal";
  5. import InfiniteScroll from "react-infinite-scroll-component";
  6.  
  7. class App extends Component {
  8.   constructor() {
  9.     super();
  10.     this.state = {
  11.       githubData: [],
  12.       count: 10,
  13.     };
  14.   }
  15.   componentDidMount() {
  16.     const { count } = this.state;
  17.  
  18.     axios
  19.       .get(
  20.         "https://api.github.com/search/repositories?q=language:Java&sort=stars&page=1&per_page=" +
  21.           count
  22.       )
  23.       .then((res) => {
  24.         console.log("res", res);
  25.         this.setState({ githubData: res.data.items });
  26.       });
  27.  
  28.   }
  29.  
  30.   fetchRepos = () => {
  31.     const { count } = this.state;
  32.     this.setState({ count: this.state.count + count });
  33.     axios
  34.       .get(
  35.         "https://api.github.com/search/repositories?q=language:Java&sort=stars&page=1&per_page=" +
  36.           count
  37.       )
  38.       .then((res) => {
  39.         console.log("res", res);
  40.         this.setState({
  41.           githubData: this.state.githubData.concat(res.data.items)
  42.         });
  43.       });
  44.   };
  45.  
  46.   render() {
  47.     const { githubData } = this.state;
  48.     return (
  49.       <div className="container">
  50.         <Navbar />
  51.         <div className="row">
  52.           <InfiniteScroll
  53.             next={this.fetchRepos}
  54.             hasMore={true}
  55.             loader={<h4>Loading...</h4>}
  56.           >
  57.             {githubData.map((name, index) => (
  58.               <div className="col-md-12" key={name.id}>
  59.                 <h1>
  60.                   Projeto:&nbsp;
  61.                   {name.name}
  62.                 </h1>
  63.               </div>
  64.             ))}
  65.           </InfiniteScroll>
  66.         </div>
  67.       </div>
  68.     );
  69.   }
  70. }
  71.  
  72. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement