2022-06-04 03:13:19 +00:00
|
|
|
import { useEffect } from "react"
|
|
|
|
import { PostcardContext } from "./PostcardContext"
|
|
|
|
import { useDefinedContext } from "../../utils/definedContext"
|
|
|
|
import { StaticImageData } from "next/image"
|
|
|
|
|
|
|
|
type PostcardProps = {
|
|
|
|
src?: string | StaticImageData
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:14:00 +00:00
|
|
|
export function Postcard({ src }: PostcardProps) {
|
|
|
|
const { setPostcard } = useDefinedContext(PostcardContext)
|
2022-06-04 03:13:19 +00:00
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => {
|
2022-06-08 17:14:00 +00:00
|
|
|
if (src) {
|
|
|
|
if (src === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (typeof src === "object") {
|
2022-06-04 03:13:19 +00:00
|
|
|
setPostcard(src.src)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setPostcard(src)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-06-08 00:41:41 +00:00
|
|
|
[src, setPostcard]
|
2022-06-04 03:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|