File tree 1 file changed +4
-5
lines changed
1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -4,20 +4,18 @@ import React from "react";
4
4
export type NextImageFromFileProps = Partial < ImageProps > &
5
5
Pick < ImageProps , "src" > ;
6
6
7
- function isImageProps ( props : NextImageFromFileProps ) : props is ImageProps {
8
- return typeof props . src !== "string" || ! ! ( props . width && props . height ) ;
9
- }
10
-
11
7
export default function NextImageFromFile ( props : NextImageFromFileProps ) {
12
8
const [ image , setImage ] = React . useState < null | {
13
9
width : number ;
14
10
height : number ;
15
11
} > ( null ) ;
16
12
17
- if ( isImageProps ( props ) ) {
13
+ // Fall back to regular next/image if all necessary props are given
14
+ if ( typeof props . src !== "string" || ( props . width && props . height ) ) {
18
15
return < Image { ...props } unoptimized /> ;
19
16
}
20
17
18
+ // No width and height available? Render raw img tag first to figure them out
21
19
if ( ! image )
22
20
return (
23
21
< img
@@ -29,6 +27,7 @@ export default function NextImageFromFile(props: NextImageFromFileProps) {
29
27
/>
30
28
) ;
31
29
30
+ // Width and height have been figured out, render the next/image
32
31
return (
33
32
< Image
34
33
{ ...props }
You can’t perform that action at this time.
0 commit comments