Both tutorial merged and working

This commit is contained in:
Luis Fernando Molina committed 2018-09-04 10:40:16 +02:00
1 parent 61896e7162
commit d1bf136b5b
6 files changed
+228 -16

No files matched your search

+15 -9
View File
@@ -1,11 +1,23 @@
import React, { Component } from 'react'
import axios from 'axios'
import { Link } from 'react-router-dom'
import Pokeball from '../pokeball.png'
import { connect } from 'react-redux'
class Home extends Component {
state = {
posts: []
}
componentDidMount(){
axios.get('https://jsonplaceholder.typicode.com/posts/')
.then(res => {
console.log(res);
this.setState({
posts: res.data.slice(0,10)
});
})
}
render(){
const { posts } = this.props
const { posts } = this.state
const postList = posts.length ? (
posts.map(post => {
return (
@@ -35,10 +47,4 @@ class Home extends Component {
}
}
const mapStateToProps = (state) => {
return {
posts: state.posts
}
}
export default connect(mapStateToProps)(Home)
export default Home