首页 > 解决方案 > 在 ReactJS 中每 30 秒调用一次 API

问题描述

我试图每 30 秒调用一次 api。我已经尝试用 setInterval 来做,但它并没有真正奏效。

有什么建议么?

 componentDidMount() {
        const {getCurrencies, setPageCount,loadData} = this.props.actions
         agent
            .get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?CMC_PRO_API_KEY=XXX')
            .then(res => {
                getCurrencies(res.body.data)
                setPageCount()
            })
            .catch(err => {
                console.log(err)
            });
    }

标签: reactjs

解决方案


推荐阅读