UNPKG

react-imported-component

Version:
30 lines (29 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImportedController = exports.HydrationState = exports.importedState = void 0; var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importStar)(require("react")); exports.importedState = (0, react_1.createContext)(undefined); var HydrationState = function (_a) { var state = _a.state, children = _a.children; return (react_1.default.createElement(exports.importedState.Provider, { value: state }, children)); }; exports.HydrationState = HydrationState; /** * @see [LazyBoundary]{@link LazyBoundary} - HydrationController is required for LazyBoundary to properly work with React>16.10 * Established a control over LazyBoundary suppressing fallback during the initial hydration * @param props * @param [props.usesHydration=true] determines of Application is rendered using hydrate */ var ImportedController = function (_a) { var children = _a.children, _b = _a.usesHydration, usesHydration = _b === void 0 ? true : _b; var _c = (0, react_1.useState)({ usesHydration: usesHydration, pastHydration: false, }), state = _c[0], setState = _c[1]; (0, react_1.useEffect)(function () { setState(function (oldState) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, oldState), { pastHydration: true })); }); }, []); return react_1.default.createElement(exports.HydrationState, { state: state }, children); }; exports.ImportedController = ImportedController;