UNPKG

@wener/console

Version:

Base console UI toolkit

26 lines (25 loc) 903 B
import React from "react"; import { usePromise } from "@wener/reaction"; import { NonIdealState } from "../../daisy/index.js"; import { resolveErrorMessage } from "../../toast/index.js"; import { LoadingIndicator } from "../components/index.js"; import { getUserStore } from "../context.js"; export const UserLoader = ({ children, load }) => { const { loading, error } = usePromise(async () => { if (!load) return; let data = await load(); data && getUserStore().getState().load(data); }, []); if (loading) { return /*#__PURE__*/ React.createElement(LoadingIndicator, null); } if (error) { return /*#__PURE__*/ React.createElement(NonIdealState, { title: "Failed to load user", description: String(resolveErrorMessage(error)) }); } return children; }; //# sourceMappingURL=UserLoader.js.map