简体   繁体   English

如何在 React/Redux 中卸载之前以 100% 显示进度条组件?

[英]How to show progress bar component at 100% before unmounting in React/Redux?

I'm showing a ProgressBar component while loading a large list.我在加载一个大列表时显示了一个 ProgressBar 组件。 When the list is loaded I want the progress bar to show 100% complete before unmounting.加载列表后,我希望进度条在卸载前显示 100% 完成。 The problem is that the code looks like this:问题是代码看起来像这样:

if(listIsLoading) {
    return (<ProgressBar listIsLoading={listIsLoading} />);
} else {
    return (<List />);
}

The 100% value gets set in the ProgressBar component when listIsloading is false.当 listIsloading 为 false 时,在 ProgressBar 组件中设置 100% 的值。 But with how it's currently set up, the ProgressBar is unmounting before it gets to show the 100%.但就目前的设置而言,ProgressBar 在显示 100% 之前正在卸载。 The list request and setting listIsLoading value is handled in a separate redux model so I can't manipulate the components from those redux functions.列表请求和设置 listIsLoading 值在单独的 redux model 中处理,因此我无法从这些 redux 函数中操作组件。

I think some delay is needed between the time the List is loaded and and the ProgressBar is unmounted.我认为在加载 List 和卸载 ProgressBar 之间需要一些延迟。 But I thought I'd check here to see if there's a more elegant solution first before adding timeouts and stuff.但我想在添加超时和其他内容之前,我会先在这里查看是否有更优雅的解决方案。

Any ideas?有任何想法吗?

How are you setting listIsLoading true or false?你如何设置 listIsLoading 真或假? a simple delay before setting to true or false should work, are you using a useEffect?设置为 true 或 false 之前的简单延迟应该有效,您使用的是 useEffect 吗?

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

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