UNPKG

reshow-return

Version:

reshow-return (simple connect component with reshow-flux)

47 lines (43 loc) 1.26 kB
import _objectWithoutProperties from "reshow-runtime/es/helpers/objectWithoutProperties"; var _excluded = ["isHydrate"]; // @ts-check import { useLoaded } from "reshow-hooks"; import useReturn from "./useReturn.mjs"; import hydrate from "./hydrate.mjs"; /** * @typedef {import('./useReturn').UseReturnPayLoad} UseReturnPayLoad */ /** * @typedef {object&UseReturnPayLoad} UseClientReturnPayLoad * @property {boolean} [isHydrate] */ /** * @template StateType * @template ActionType * * @callback UseClientReturnType * @param {import('./connectOptions').InitStatesType?} initStates * @param {import("reshow-flux-base").StoreObject<StateType, ActionType>} store * @param {UseClientReturnPayLoad} [payload] * * @returns {StateType} * */ /** * @type {UseClientReturnType<any, any>} */ var useClientReturn = function useClientReturn(initStates, store, payload) { var _ref = payload || {}, { isHydrate } = _ref, restpayload = _objectWithoutProperties(_ref, _excluded); if (hydrate() || isHydrate) { var state = useReturn(initStates, store, restpayload); var isLoad = useLoaded(); return isLoad ? state : {}; } else { return useReturn(initStates, store, restpayload); } }; export default useClientReturn;