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

20 lines
515 B
TypeScript
Raw Permalink Normal View History

2022-06-11 03:08:49 +00:00
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()
}