1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 14:44:21 +00:00
festa/components/generic/loading/swr.tsx

19 lines
515 B
TypeScript

import { SWRResponse } from "swr";
export type SWRMultiplexerConfig<D, E = Error> = {
hook: SWRResponse<D, E>,
loading: () => JSX.Element,
ready: (data: D) => JSX.Element,
error: (error: E) => JSX.Element,
}
export function swrMultiplexer<D, E = Error>(config: SWRMultiplexerConfig<D, E>): JSX.Element {
if (config.hook.error) {
return config.error(config.hook.error)
}
if (config.hook.data) {
return config.ready(config.hook.data)
}
return config.loading()
}