spermspace

Untitled

Jul 19th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react"
  2. import ReactDOM from "react-dom"
  3. import axios from "axios"
  4.  
  5. class AjaxAxios extends React.Component {
  6.   state = {
  7.     posts: []
  8.   }
  9.   componentDidMount() {
  10.     axios.get('http://127.0.0.1:8000/api/v1/?format=json'.json)
  11.       .then(res => {
  12.         const posts = res.data.data.children.map(obj => obj.data);
  13.  
  14.         this.setState({
  15.           posts
  16.         });
  17.  
  18.       })
  19.   }
  20.   render(){
  21.     return(
  22.       <div>
  23.         <ul>
  24.           {this.state.posts.map(post =>
  25.             <a key={post.id} className="title" href="/{post.section}/{post.slug}">{post.title}</a>
  26.             // <span key={post.id} className="time_pub">{ post.timestamp }</span>
  27.             // <span key={post.id} className="section"><a href="/{ n.section }">{ post.section }</a></span>
  28.           )}
  29.         </ul>
  30.       </div>
  31.     );
  32.   }
  33. }
  34.  
  35.  
  36. const wrapper = document.getElementById("root");
  37. wrapper ? ReactDOM.render(<AjaxAxios />, wrapper) : null;
Add Comment
Please, Sign In to add comment