Get all doc data from collection seremon firestore

我的未来我决定 提交于 2021-02-11 12:48:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!