What is wrong in what i am doing, i am getting collection snapshot, looping through it and push it to the state then use that state to render some list items
but i get that error:
Unhandled Rejection (TypeError): Cannot read property 'map' of undefined
Code:
const [books, setBooks] = useState([]);
db.collection('books').get()
.then(snapshot => snapshot.forEach(doc => {
setBooks([...books, doc.data()])
}))
return (
books.map(return some jsx)
)
books && books.map(return some jsx)?setBooks([])in forEach and log thedocanddoc.data()