2022-07-20 21:53:08 +00:00
|
|
|
import { StaticImageData } from "next/image"
|
2022-06-11 03:08:49 +00:00
|
|
|
import { useEffect } from "react"
|
|
|
|
import { useDefinedContext } from "../../utils/definedContext"
|
|
|
|
import { PostcardContext, PostcardSource } from "./base"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use the passed src as {@link PostcardSource} for the wrapping {@link PostcardContext}.
|
|
|
|
*/
|
2022-07-20 21:53:08 +00:00
|
|
|
export function usePostcardImage(src: PostcardSource | StaticImageData) {
|
|
|
|
const { changePostcard } = useDefinedContext(PostcardContext)
|
2022-06-11 03:08:49 +00:00
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => {
|
2022-07-20 22:30:09 +00:00
|
|
|
changePostcard(src)
|
2022-06-11 03:08:49 +00:00
|
|
|
},
|
2022-07-20 21:53:08 +00:00
|
|
|
[src, changePostcard]
|
2022-06-11 03:08:49 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The same as {@link usePostcardImage}, but as a component rendering `null`.
|
|
|
|
*/
|
2022-07-20 21:53:08 +00:00
|
|
|
export function Postcard({ src }: { src: PostcardSource | StaticImageData }): null {
|
|
|
|
usePostcardImage(src)
|
2022-06-11 03:08:49 +00:00
|
|
|
return null
|
|
|
|
}
|