lbry-desktop/ui/component/fileThumbnail/FreezeframeWrapper.jsx

37 lines
935 B
React
Raw Normal View History

import React, { useEffect } from 'react';
2020-05-28 19:07:04 +02:00
import classnames from 'classnames';
import PropTypes from 'prop-types';
import Freezeframe from './FreezeframeLite';
2021-04-14 21:02:02 +02:00
import useLazyLoading from 'effects/use-lazy-loading';
const FreezeframeWrapper = (props) => {
const imgRef = React.useRef();
const freezeframe = React.useRef();
// eslint-disable-next-line
const { src, className, children } = props;
const srcLoaded = useLazyLoading(imgRef);
useEffect(() => {
if (srcLoaded) {
freezeframe.current = new Freezeframe(imgRef.current);
}
}, [srcLoaded]);
return (
2020-05-28 19:07:04 +02:00
<div className={classnames(className, 'freezeframe-wrapper')}>
<>
<img ref={imgRef} data-src={src} className="freezeframe-img" />
{children}
</>
</div>
);
};
FreezeframeWrapper.propTypes = {
src: PropTypes.string.isRequired,
className: PropTypes.string.isRequired,
};
export default FreezeframeWrapper;