const [theposts, setThePosts] = useState([]);
const myPosts = query(collectionGroup(db, 'posts'));
const unsub = onSnapshot(myPosts, (querySnapshot) => {
querySnapshot.forEach((doc) => setThePosts({
post: doc.data()
}))
return unsub;
})
const Posts = theposts.post;
return (
<>
<StatusBar barStyle = "dark-content" backgroundColor = {'#b300b3'} />
<SafeAreaView style={[styles.container, {marginTop: 5}]}>
<Header navigation = {navigation} />
<Stories />
<ScrollView>
{Posts.map((post, index) => (
<Post post={post} key = {index} />
))}
</ScrollView>
{ /* <BottomTabs icons={bottomTabsIcons} /> */ }
</SafeAreaView>
</>
)
It seems like there’s no better way to write this, but still, it either gives an error(1): undefined is not a function (near’…Post.map’)
OR
error(2): theposts.postes is not a function. theposts.postes is undefined