UNPKG

opds-web-client

Version:
26 lines (25 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useActions = exports.ActionsProvider = exports.ActionsContext = void 0; var React = require("react"); var useThunkDispatch_1 = require("../../hooks/useThunkDispatch"); exports.ActionsContext = React.createContext(undefined); function ActionsProvider(_a) { var children = _a.children, actions = _a.actions, fetcher = _a.fetcher; return (React.createElement(exports.ActionsContext.Provider, { value: { actions: actions, fetcher: fetcher } }, children)); } exports.ActionsProvider = ActionsProvider; /** * Custom hook used for getting access to the available Actions. */ function useActions() { var context = React.useContext(exports.ActionsContext); var dispatch = (0, useThunkDispatch_1.default)(); if (typeof context === "undefined") { throw new Error("useActions must be used within a ActionsProvider"); } var actions = context.actions, fetcher = context.fetcher; return { actions: actions, fetcher: fetcher, dispatch: dispatch }; } exports.useActions = useActions; exports.default = exports.ActionsContext;