簡體   English   中英

加載微調器永遠加載

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM