File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 1
1
import Image , { ImageProps } from "next/image" ;
2
2
import React from "react" ;
3
3
4
- export default function NextImageFromFile ( props : ImageProps ) {
4
+ export type NextImageFromFileProps = Partial < ImageProps > &
5
+ Pick < ImageProps , "src" > ;
6
+
7
+ function isImageProps ( props : NextImageFromFileProps ) : props is ImageProps {
8
+ return typeof props . src !== "string" || ! ! ( props . width && props . height ) ;
9
+ }
10
+
11
+ export default function NextImageFromFile ( props : NextImageFromFileProps ) {
5
12
const [ image , setImage ] = React . useState < null | {
6
13
width : number ;
7
14
height : number ;
8
15
} > ( null ) ;
9
16
10
- if ( typeof props . src !== "string" || ( props . width && props . height ) ) {
17
+ if ( isImageProps ( props ) ) {
11
18
return < Image { ...props } unoptimized /> ;
12
19
}
13
20
You can’t perform that action at this time.
0 commit comments