[英]loading spinner keeps loading forever React
我的装载机微调器有问题。 它一直在加载,即使我宣布它的时间是 2 秒,但没有任何反应。 这是我的代码:
import Loading from './Loading';
const ItemDetailContainer = () => {
const [arrayList, setArrayList] = useState({});
const [loading, SetLoading] = useState(false);
useEffect(() => {
SetLoading(true);
customFetch(2000, products[0])
.then((result) => setArrayList(result))
.catch((err) => console.log(err));
}, []);
return (
<div>
{loading ? <Loading/> : <ItemDetail products={arrayList}/>}
</div>
);
};
您在组件安装时SetLoading(true)
但当customFetch
返回时您永远不会SetLoading(false)
回到 false。
useEffect(() => {
SetLoading(true);
customFetch(2000, products[0])
.then((result) => setArrayList(result))
.catch((err) => console.log(err))
.finally(() => SetLoading(false));
}, []);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.