Skip to content

Instantly share code, notes, and snippets.

@DragonFyZex
Created September 20, 2018 03:14
Show Gist options
  • Save DragonFyZex/ea112ae36a0a768b23415b934cf34c95 to your computer and use it in GitHub Desktop.
Save DragonFyZex/ea112ae36a0a768b23415b934cf34c95 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
class Reddit extends React.Component
{
state = {
posts: [],
coolthing: []
}
componentDidMount()
{
axios.get(`https://www.reddit.com/r/dota2.json`)
.then(res => {
const posts = res.data.data.children.map(obj=> obj.data);
this.setState({posts});
})
}
render() {
const used = [];
return(
<div>
{this.state.posts.map(post => (
<li key={post.id}> {post.preview.images[0].id} </li>
))}
</div>
)
}
}
ReactDOM.render(<Reddit/>, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment