Skip to content

Commit 9fec53a

Browse files
committed
Remove useIsLoaded and useIsLoading hooks
1 parent bee2c22 commit 9fec53a

3 files changed

Lines changed: 13 additions & 76 deletions

File tree

src/components/EmbeddedVideo.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use client';
22

33
import classNames from 'classnames';
4-
import React, { useRef } from 'react';
4+
import React, { useState } from 'react';
55
import LoadingSpinner from './LoadingSpinner';
6-
import { useIsLoading } from '../hooks';
76

87
const sizes = Object.freeze({
98
xs: {
@@ -31,10 +30,8 @@ const sizes = Object.freeze({
3130
export interface EmbeddedVideoProps {
3231
allowFullScreen?: boolean;
3332
className?: string;
34-
frameBorder?: string;
3533
height?: string | number;
3634
id?: string;
37-
scrolling?: string;
3835
size?: keyof typeof sizes;
3936
src: string;
4037
title?: string;
@@ -44,17 +41,14 @@ export interface EmbeddedVideoProps {
4441
export default function EmbeddedVideo({
4542
allowFullScreen = true,
4643
className,
47-
frameBorder = '0',
4844
height,
4945
id = 'video-player',
50-
scrolling = 'no',
5146
size,
5247
src,
5348
title = 'Video Player',
5449
width,
5550
}: EmbeddedVideoProps) {
56-
const ref = useRef<HTMLIFrameElement>(null);
57-
const loading = useIsLoading(ref);
51+
const [loading, setLoading] = useState(true);
5852
const offline = typeof navigator !== 'undefined' && !navigator.onLine;
5953
const _width = width || (size && sizes[size].width);
6054
const _height = height || (size && sizes[size].height);
@@ -73,11 +67,9 @@ export default function EmbeddedVideo({
7367
>
7468
<iframe
7569
allowFullScreen={allowFullScreen}
76-
frameBorder={frameBorder}
7770
height={_height || '100%'}
7871
id={id}
79-
ref={ref}
80-
scrolling={scrolling}
72+
onLoad={e => setLoading(false)}
8173
src={src}
8274
title={title}
8375
width={_width || '100%'}

src/components/ProgressiveImage.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use client';
22

33
import classNames from 'classnames';
4-
import React, { useRef } from 'react';
4+
import React, { useEffect, useState } from 'react';
55
import LoadingSpinner from './LoadingSpinner';
6-
import { useIsLoaded } from '../hooks';
76

87
export type ProgressiveImageProps = {
98
alt?: string;
@@ -41,8 +40,14 @@ export default function ProgressiveImage({
4140
width,
4241
...rest
4342
}: ProgressiveImageProps) {
44-
const imageRef = useRef<HTMLImageElement>(null);
45-
const loaded = useIsLoaded(imageRef, undefined, onLoad);
43+
const [loaded, setLoaded] = useState(false);
44+
45+
useEffect(() => {
46+
if (loaded && onLoad) {
47+
onLoad();
48+
}
49+
}, [loaded]);
50+
4651
return (
4752
<picture
4853
className={classNames(
@@ -66,9 +71,9 @@ export default function ProgressiveImage({
6671
imageProps.className,
6772
{ [`object-${objectFit}`]: objectFit },
6873
)}
74+
onLoad={e => setLoaded(true)}
6975
width={width || imageProps.width}
7076
height={height || imageProps.height}
71-
ref={imageRef}
7277
src={src}
7378
/>
7479
{placeholder && (

src/hooks/useIsLoaded.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)