remotion
Version:
Render videos in React
31 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Img = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ready_manager_1 = require("./ready-manager");
const ImgRefForwarding = ({ onLoad, onError, ...props }, ref) => {
const [handle] = react_1.useState(() => ready_manager_1.delayRender());
react_1.useEffect(() => {
if (ref &&
ref.current.complete) {
ready_manager_1.continueRender(handle);
}
}, [handle, ref]);
const didLoad = react_1.useCallback((e) => {
ready_manager_1.continueRender(handle);
onLoad === null || onLoad === void 0 ? void 0 : onLoad(e);
}, [handle, onLoad]);
const didGetError = react_1.useCallback((e) => {
ready_manager_1.continueRender(handle);
if (onError) {
onError(e);
}
else {
console.error('Error loading image:', e, 'Handle the event using the onError() prop to make this message disappear.');
}
}, [handle, onError]);
return jsx_runtime_1.jsx("img", Object.assign({}, props, { ref: ref, onLoad: didLoad, onError: didGetError }), void 0);
};
exports.Img = react_1.forwardRef(ImgRefForwarding);
//# sourceMappingURL=Img.js.map