UNPKG

1.04 kBJavaScriptView Raw
1import React, { useState, useEffect } from "react";
2import loading2 from "../assets/images/loading2.gif";
3import { Empty } from "antd";
4
5/**
6 * ----------------------------------------
7 * 显示正在加载
8 * @param {null} data - 如果data是null,则显示正在加载,否则显示children
9 * @param {Boolean} empty - 如果
10 * ----------------------------------------
11 */
12export default function NullLoading({ data, children, empty }) {
13 const [v, set] = useState(data);
14
15 useEffect(() => {
16 if (data) {
17 setTimeout(() => {
18 set(data);
19 }, 200);
20 }
21 }, [data]);
22
23 if (v !== null) {
24 if (empty && Array.isArray(v) && v.length === 0) {
25 return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
26 }
27 return children;
28 }
29
30 return (
31 <div
32 style={{
33 height: "150px",
34 width: "100%",
35 background: "white",
36 display: "flex",
37 alignItems: "center",
38 justifyContent: "center",
39 }}
40 >
41 <img src={loading2} width="16" />
42 </div>
43 );
44}