问题
function Sermons() {
const [{globalSeremon}, dispatch] = useStateValue()
const [seremons, setSeremons] = useState([])
const [loading, setLoading] = useState(false)
useEffect(() => {
db.collection('sermons')
.orderBy("date", "desc")
.get()
.then((snapshot) => {
const localseremons = []
snapshot.forEach(doc => {
localseremons.push(doc.data())
})
setSeremons(localseremons)
})
.catch(e => console.log(e))
})
return (
<div>
<Header/>
<div className='container-lg seremon_container'>
{seremons.map(seremon => (
<a className='seremon_link' key={seremon.img} onClick={addSeremon}>
<div className='seremon'>
<img className='seremon_img contai' src={seremon.img}/>
<div className='details'>
<h3 className='seremon_title'>{seremon.title}</h3>
<p className='seremon_detail seremon_date'>
{seremon.date}
</p>
<p className='seremon_worship seremon_detail'>{seremon.worship}</p>
</div>
</div>
</a>
))}
</div>
</div>
)
}
And also if you can add an onClick function to the seremon.link to find out which of the seremon the user clicked on
来源:https://stackoverflow.com/questions/66026503/get-all-doc-data-from-collection-seremon-firestore