Rewrite Image component as function component (#24893)
This commit is contained in:
parent
490ccbf40b
commit
a65d2d1045
2 changed files with 27 additions and 33 deletions
27
app/javascript/mastodon/components/image.tsx
Normal file
27
app/javascript/mastodon/components/image.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
import React, { useCallback, useState } from 'react';
|
||||
import Blurhash from './blurhash';
|
||||
import classNames from 'classnames';
|
||||
|
||||
type Props = {
|
||||
src: string;
|
||||
srcSet?: string;
|
||||
blurhash?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const Image: React.FC<Props> = ({ src, srcSet, blurhash, className }) => {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
const handleLoad = useCallback(() => {
|
||||
setLoaded(true);
|
||||
}, [setLoaded]);
|
||||
|
||||
return (
|
||||
<div className={classNames('image', { loaded }, className)} role='presentation'>
|
||||
{blurhash && <Blurhash hash={blurhash} className='image__preview' />}
|
||||
<img src={src} srcSet={srcSet} alt='' onLoad={handleLoad} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Image;
|
Loading…
Add table
Add a link
Reference in a new issue