mirror of
https://github.com/Steffo99/festa.git
synced 2024-10-16 23:17:26 +00:00
34 lines
703 B
TypeScript
34 lines
703 B
TypeScript
|
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)
|
||
|
},
|
||
|
[src]
|
||
|
)
|
||
|
}
|
||
|
|
||
|
|
||
|
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
|
||
|
}
|