import { SWRResponse } from "swr"; export type SWRMultiplexerConfig = { hook: SWRResponse, loading: () => JSX.Element, ready: (data: D) => JSX.Element, error: (error: E) => JSX.Element, } export function swrMultiplexer(config: SWRMultiplexerConfig): 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() }