I follow the react-redux tutorial and I try to display post. I get the post data from https://jsonplaceholder.typicode.com/posts. it returns the response like this:
import React from 'react';
import { connect } from 'react-redux';
import { fetchPost } from '../actions'
class PostList extends React.Component{
componentDidMount(){
this.props.fetchPost();
}
renderList(){
return this.props.post.map(pos => {
return (
<div className="item" key={pos.id}>
<p>{pos.title}</p>
</div>
);
});
}
render(){
return(<div className="ui relaxed divided list"> {this.renderList()} </div>);
}
}
const mapStateToProps = (state) =>{
return { post:state.post}
}
export default connect(mapStateToProps , { fetchPost })(PostList);
this is my action creater
import JsonPlaceHolder from '../apis/JsonPlaceHolder'
export const fetchPost = () => {
return async (dispatch) => {
const response = await JsonPlaceHolder.get('/posts');
dispatch({
type: 'FETCH_POST',
payload:response
});
}
};
this is my reducer
export default (state=[],action) => {
switch(action.type){
case "FETCH_POST":
return action.payload;
default:
return state;
}
};
this is my ../apis/JsonPlaceHolder file
import axios from 'axios';
export default axios.create({
baseURL:"https://jsonplaceholder.typicode.com/"
});
but i get the error like this
TypeError: this.props.post.map is not a function

../apis/JsonPlaceHolderfile