Skip to content

Commit

Permalink
feat(project): add width and height to logo img
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Jul 19, 2021
1 parent b987c38 commit df27e8e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/components/Logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useRef } from 'react';
import { Link } from 'react-router-dom';

import styles from './Logo.module.scss';
Expand All @@ -8,10 +8,31 @@ type Props = {
onLoad: () => void;
};

type ImgRef = {
height?: number;
width?: number;
};

const Logo: React.FC<Props> = ({ src, onLoad }: Props) => {
const imgRef = useRef<ImgRef>({ height: undefined, width: undefined });

const onLoadHandler = (event: React.SyntheticEvent<HTMLImageElement, Event>) => {
const { height, width } = event.currentTarget;
imgRef.current = { height, width };
onLoad();
};

return (
<Link to="/">
<img className={styles.logo} alt="logo" src={src} onLoad={onLoad} onError={onLoad} />
<img
className={styles.logo}
alt="logo"
src={src}
height={imgRef.current.height}
width={imgRef.current.width}
onLoad={onLoadHandler}
onError={onLoad}
/>
</Link>
);
};
Expand Down

0 comments on commit df27e8e

Please sign in to comment.