简体   繁体   English

React-redux 应用程序不会刷新延迟存储

[英]React-redux app is not refreshing stored with delay

I'm using React JS for my web app.我正在为我的 Web 应用程序使用 React JS。

It gets data from the API using Redux and Axios.它使用 Redux 和 Axios 从 API 获取数据。

When I enter to some profile page in app, It gets data from the API and renders the page.当我进入应用程序中的某个个人资料页面时,它从 API 获取数据并呈现页面。

The problem is, when I go to another profile, it first opens the page with previous profile's data, then after 2-3 seconds the information changes into the newly fetched data.问题是,当我转到另一个配置文件时,它首先打开包含先前配置文件数据的页面,然后在 2-3 秒后信息更改为新获取的数据。

In some components the change does not happen and they show previous information.在某些组件中,更改不会发生,它们会显示以前的信息。 Only after 2-3 refreshes you see the change.只有在 2-3 次刷新后,您才能看到更改。

Almost all of my API interaction functions are async functions.我几乎所有的 API 交互函数都是异步函数。

What am I doing wrong?我究竟做错了什么?

I'm new to React, I don't know what part of code to paste here for more details.我是 React 的新手,我不知道要粘贴哪部分代码以获取更多详细信息。 Have no clue what this issue might be connected with.不知道这个问题可能与什么有关。

Your 2 triggers of going to a new profile page and calling fetch are called together.转到新的个人资料页面和调用 fetch 的 2 个触发器被一起调用。 You need to separate them.你需要把它们分开。 Option 1: Show new page, then loading, then fetched profile.选项 1:显示新页面,然后加载,然后获取配置文件。 Option 2: Show loading, wait for the fetch to succeed, then switch.方案二:显示loading,等待fetch成功,再切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM