mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-23 07:04:22 +00:00
20 lines
515 B
TypeScript
20 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()
|
||
|
}
|