We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 27cd51f commit a6050a7Copy full SHA for a6050a7
src/index.tsx
@@ -1,13 +1,20 @@
1
import Image, { ImageProps } from "next/image";
2
import React from "react";
3
4
-export default function NextImageFromFile(props: ImageProps) {
+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) {
12
const [image, setImage] = React.useState<null | {
13
width: number;
14
height: number;
15
}>(null);
16
- if (typeof props.src !== "string" || (props.width && props.height)) {
17
+ if (isImageProps(props)) {
18
return <Image {...props} unoptimized />;
19
}
20
0 commit comments