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}.
|
|
|
|
*/
|
|
|
|
export function usePostcardImage(src: PostcardSource) {
|
|
|
|
const { setSrc } = useDefinedContext(PostcardContext)
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => {
|
|
|
|
setSrc(src)
|
|
|
|
},
|
2022-07-16 14:06:07 +00:00
|
|
|
[src, setSrc]
|
2022-06-11 03:08:49 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export type PostcardProps = {
|
|
|
|
src: PostcardSource
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The same as {@link usePostcardImage}, but as a component rendering `null`.
|
|
|
|
*/
|
|
|
|
export function Postcard(props: PostcardProps) {
|
|
|
|
usePostcardImage(props.src)
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|