1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-10-16 15:07:27 +00:00
festa/components/postcard/changer.tsx

34 lines
903 B
TypeScript
Raw Normal View History

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}.
*/
export function usePostcardImage(src: PostcardSource | StaticImageData) {
const { changePostcard } = useDefinedContext(PostcardContext)
2022-06-11 03:08:49 +00:00
useEffect(
() => {
if (typeof src === "string") {
changePostcard(src)
}
else {
changePostcard(src.src)
}
2022-06-11 03:08:49 +00:00
},
[src, changePostcard]
2022-06-11 03:08:49 +00:00
)
}
/**
* The same as {@link usePostcardImage}, but as a component rendering `null`.
*/
export function Postcard({ src }: { src: PostcardSource | StaticImageData }): null {
usePostcardImage(src)
2022-06-11 03:08:49 +00:00
return null
}