【问题标题】:React API call status is pending foreverReact API 调用状态永远挂起
【发布时间】:2021-10-12 01:51:21
【问题描述】:

I am making API calls from my CRA (Create React App). Sometimes while opening a random page all of the API calls are showing the status of "pending" forever. When I refresh my page then, all the APIs work fine.

These are the details of the API in "pending" status.

const checkWelcomeRewardShown = async () => {
    try {
        if (localStorage.getItem("userType") === "student") {
            let res = await axios.get(`${process.env.REACT_APP_BASE_URL}/api/gethasnotseenintro`);
            if (res?.data?.status === "success" && res?.data?.notSeen) {
                await axios.get(`${process.env.REACT_APP_BASE_URL}/api/getunlocktokenuser`);

                await axios.get(`${process.env.REACT_APP_BASE_URL}/api/falsewhenfirstlogin`);
            }

            let response = await axios.get(`${process.env.REACT_APP_BASE_URL}/api/seenPopupForLinkedinAndFeedback`);
        }
    } catch (error) {}
};

useEffect(() => {
    checkWelcomeRewardShown();
    dispatch(showAllPopups());
}, [localStorage.getItem("user_id")]);

【问题讨论】:

    标签: node.js reactjs api routes axios


    【解决方案1】:

    解决了。后端中有一个 API 失败了,如果失败了会发生什么,没有逻辑。这就像一个在任何地方都在使用的全局级 API,所以当它失败时,它会阻止其余 API 的执行。这就是为什么它们都显示“待处理”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多