LoadingCircular.jsx 1020 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React, {useEffect, useState} from "react";
  2. import {CircularProgress} from "@mui/material";
  3. const LoadingCircular=()=>{
  4. const [isShow, setIsShow] = useState(false);
  5. const [showMask,setShowMask]=useState(false);
  6. const show=(showMask=false)=>{
  7. setIsShow(true);
  8. setShowMask(showMask);
  9. }
  10. const hide=()=>{
  11. setIsShow(false);
  12. }
  13. useEffect(()=>{
  14. const loadingCircular={
  15. show,
  16. hide
  17. };
  18. global.loadingCircular=loadingCircular;
  19. return () => {
  20. if (global.loadingCircular === loadingCircular) delete global.loadingCircular;
  21. };
  22. },[])
  23. return (
  24. <>
  25. {
  26. isShow? (
  27. <div className={`loading-circular ${showMask?'loading-circular_mask':''}`}>
  28. <CircularProgress color="success" size={40} thickness={4}/>
  29. </div>
  30. ):(<></>)
  31. }
  32. </>
  33. )
  34. }
  35. export default LoadingCircular;