UNPKG

@automattic/social-previews

Version:

A suite of components to generate previews for a post for both social and search engines.

28 lines 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const i18n_1 = require("@wordpress/i18n"); const react_1 = require("react"); const constants_1 = require("../../constants"); const useImage = ({ mode: initialMode }) => { const [mode, setMode] = (0, react_1.useState)(initialMode); const [isLoadingImage, setLoadingImage] = (0, react_1.useState)(true); const onLoad = (0, react_1.useCallback)(({ target }) => { if (!mode) { const image = target; setMode(image.naturalWidth > image.naturalHeight ? constants_1.LANDSCAPE_MODE : constants_1.PORTRAIT_MODE); } setLoadingImage(false); }, [mode]); const onError = (0, react_1.useCallback)(() => setLoadingImage(false), []); return [ mode, isLoadingImage, { alt: (0, i18n_1.__)('Facebook Preview Thumbnail', 'social-previews'), onLoad, onError, }, ]; }; exports.default = useImage; //# sourceMappingURL=use-image-hook.js.map