gpt4 book ai didi

javascript - React - 在 DOM 渲染时加载屏幕?

转载 作者:行者123 更新时间:2023-12-02 23:41:00 29 4
gpt4 key购买 nike

我想显示加载屏幕直到 DOM 渲染完毕。在我的程序中。我正在检查是否有设备,那么它应该显示加载页面,直到渲染 DOM,否则显示未找到设备。

但是页面显示找不到设备,然后在渲染 DOM 后它会显示设备。如果在渲染 DOM 之前有设备,我该如何解决这个问题并显示“正在加载”消息。

渲染设备也需要时间。所以我无法检查是否有设备 - 这就是它首先显示“未找到设备”的原因。

render() {
const { devices } = this.props;

if (this.state.isLoading) {
return (
<div>Loading!!!!!</div>
);
}
if (devices && devices.length > 0) {
return (
<div> // Devices table will be displayed
</div>
);
} else {
return (
<div>
No Devices found
</div>
);
}
}

最佳答案

render() {
const { devices } = this.props;

if (devices && devices.length > 0) {
return (
<div> // Devices table will be displayed
</div>
);
}else {
if(this.state.loading){ //Not sure how you set the state
return ( <div>Loading...</div>)
}

return (
<div>
No Devices found
</div>
);
}
}

关于javascript - React - 在 DOM 渲染时加载屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56084979/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com