UNPKG

1.34 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Img = void 0;
4const jsx_runtime_1 = require("react/jsx-runtime");
5const react_1 = require("react");
6const ready_manager_1 = require("./ready-manager");
7const ImgRefForwarding = ({ onLoad, onError, ...props }, ref) => {
8 const [handle] = (0, react_1.useState)(() => (0, ready_manager_1.delayRender)());
9 (0, react_1.useEffect)(() => {
10 if (ref &&
11 ref.current.complete) {
12 (0, ready_manager_1.continueRender)(handle);
13 }
14 }, [handle, ref]);
15 const didLoad = (0, react_1.useCallback)((e) => {
16 (0, ready_manager_1.continueRender)(handle);
17 onLoad === null || onLoad === void 0 ? void 0 : onLoad(e);
18 }, [handle, onLoad]);
19 const didGetError = (0, react_1.useCallback)((e) => {
20 (0, ready_manager_1.continueRender)(handle);
21 if (onError) {
22 onError(e);
23 }
24 else {
25 console.error('Error loading image:', e, 'Handle the event using the onError() prop to make this message disappear.');
26 }
27 }, [handle, onError]);
28 return (0, jsx_runtime_1.jsx)("img", Object.assign({}, props, { ref: ref, onLoad: didLoad, onError: didGetError }), void 0);
29};
30exports.Img = (0, react_1.forwardRef)(ImgRefForwarding);
31//# sourceMappingURL=Img.js.map
\No newline at end of file