简体   繁体   中英

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. 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.

useEffect(() => {
  SetLoading(true);
  customFetch(2000, products[0])
    .then((result) => setArrayList(result))
    .catch((err) => console.log(err))
    .finally(() => SetLoading(false));
}, []);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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