import React, { FC, useCallback, useEffect, useRef, useState } from 'react'; import classNames from 'classnames'; import { PRESETS } from '~/constants/urls'; import { IUser } from '~/types/auth'; import { getURL } from '~/utils/dom'; import styles from './styles.module.scss'; interface IProps { cover: IUser['cover']; } const CoverBackdrop: FC = ({ cover }) => { const ref = useRef(null); const [is_loaded, setIsLoaded] = useState(false); const onLoad = useCallback(() => setIsLoaded(true), [setIsLoaded]); const image = getURL(cover, PRESETS.cover); useEffect(() => { if (!cover || !cover.url || !ref || !ref.current) return; ref.current.src = ''; setIsLoaded(false); ref.current.src = getURL(cover, PRESETS.cover); }, [cover]); if (!cover) return null; return (
{ // TODO: use ImageWithSSRLoad here if you will face any bugs }
); }; export { CoverBackdrop };