-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathBlogs.js
More file actions
39 lines (37 loc) · 1004 Bytes
/
Copy pathBlogs.js
File metadata and controls
39 lines (37 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useEffect, useState } from "react";
import axios from "axios";
import Blog from "./Blog";
import config from "../config";
const Blogs = () => {
const [blogs, setBlogs] = useState();
console.log("hi")
const sendRequest = async () => {
const res = await axios
.get(`${config.BASE_URL}/api/blogs`)
.catch((err) => console.log(err));
const data = await res.data;
console.log(data.data.blogs)
return data;
};
useEffect(() => {
sendRequest().then((data) => setBlogs(data.data.blogs));
}, []);
console.log(blogs);
return (
<div>
{blogs &&
blogs.map((blog, index) => (
<Blog
id={blog._id}
isUser={localStorage.getItem("userId") === blog.user._id}
title={blog.title}
desc={blog.desc}
img={blog.img}
user={blog.user.name}
date={new Date(blog.date).toLocaleDateString()}
/>
))}
</div>
);
};
export default Blogs;