Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 19th, 2018 62 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. import React, { Component } from "react";
  2. import "./App.css";
  3.  
  4. class App extends React.Component {
  5.  constructor() {
  6.         super();
  7.         this.state = {
  8.           items: [],
  9.           totalPages: '',
  10.           nextPage: '',
  11.         };
  12.         this._loadData = this._loadData.bind(this);
  13.       }
  14.       componentDidMount() {
  15.         const url = 'http://localhost/wp-json/wp/v2/';
  16.         this._loadData(url);
  17.  
  18.       }
  19.       _loadData(url) {
  20.         request.get(url).then((response) => {
  21.           this.setState({
  22.             items: response.body.items.data,
  23.             totalPages: response.body.items.last_page,
  24.             nextPage: response.body.items.next_page_url
  25.           });
  26.         });
  27.       }
  28.       render() {
  29.         let items = _.map(this.state.items, (item) => {
  30.         return (
  31.                 <div key={item.id}>
  32.                         <div className="content">
  33.                             <span>
  34.                                 {item.type}
  35.                             </span>
  36.  
  37.                         </div>
  38.                 </div>
  39.         )
  40.     });
  41.         return (
  42.             <div>
  43.                {items}
  44.             </div>
  45.  
  46.             <div>
  47.                <a href="#0" onClick={this._loadData(this.state.nextPage)}/>Next
  48.             </div>
  49.       }
  50. }
  51.  
  52. export default App;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top