简体   繁体   English

加载微调器永远加载

[英]loading spinner keeps loading forever React

I've got a problem with my loader spinner.我的装载机微调器有问题。 It keeps loading forever, even though i declared it's time to 2s in the fetch, but nothing happens.它一直在加载,即使我宣布它的时间是 2 秒,但没有任何反应。 Here's my code:这是我的代码:

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>
    );
  };

You SetLoading(true) when the component mounts but when customFetch returns you never SetLoading(false) back to false.您在组件安装时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.

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