Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {useState, useEffect} from 'react';
- import axios from 'axios';
- import Post from "./Post"
- import './PostList_style.css'
- function PostList(props) {
- const [post_list, set_post_list] = useState([]);
- const get_posts = () =>{
- axios.get('http://127.0.0.1:8000/api/posts/')
- .then(res => set_post_list(res.data))
- .catch(err => console.log(err))
- };
- useEffect(()=>{
- get_posts()
- }, []);
- return (
- <div className="post_list_layout">
- {post_list.map(post_data => <Post key={post_data.id} data={post_data}/>)}
- </div>
- );
- }
- export default PostList;
Add Comment
Please, Sign In to add comment