Logging the results of the firestore query yields all the data I needed, however using setPosts to store it in the "posts" variable returns undefined. I'm sure I'm missing something obvious...
const Posts = () => {
const [posts, setPosts] = useState();
useEffect(() => {
db.collection('posts')
.get()
.then((data) => {
const results = data.docs.map((doc) => doc.data())
console.log(results);
// (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
setPosts(results);
console.log(posts);
// undefined - why?
})
.catch((error) => {
console.error(error);
});
}, []);
return ()};