MCPcopy Create free account
hub / github.com/DTStack/dt-react-component / useImage

Function useImage

src/image/index.tsx:26–45  ·  view source on GitHub ↗
({ src }: { src: string })

Source from the content-addressed store, hash-verified

24}
25
26export function useImage({ src }: { src: string }): {
27 src: string | undefined;
28 isLoading: boolean;
29} {
30 const [loading, setLoading] = React.useState(true);
31 const [value, setValue] = React.useState<string | undefined>(undefined);
32
33 React.useEffect(() => {
34 loadImage(src)
35 .then(() => {
36 setLoading(false);
37 setValue(src);
38 })
39 .finally(() => {
40 setLoading(false);
41 });
42 }, [src]);
43
44 return { isLoading: loading, src: value };
45}
46
47const ImageComponent = (props: IProps) => {
48 const { lazy } = props;

Callers 1

NormalImageFunction · 0.85

Calls 2

loadImageFunction · 0.85
setValueFunction · 0.85

Tested by

no test coverage detected