Here's my code:
useEffect(() => {
fetchPosts()
}, [])
const [posts, setPosts] = useState([])
const fetchPosts = async () => {
const data = await fetch('https://jsonplaceholder.typicode.com/posts?_limit=10')
const posts_data = await data.json()
setPosts(posts_data)
console.log(posts)
}
From the console.log(posts)
it says []
with a length: 0
inside. However when I console log posts_data
it then gives me all the posts
I got from that api call. Is the setPosts
not working?
UPDATE
I even added:
<div className="container-fluid mt-3">
<h1 className="text-white">Posts</h1>
{posts.map(post => {
<p>asdasd</p>
})}
</div>
And it doesn't display anything.
something
`). – Brian Thompson Nov 10 '20 at 17:48