react-imported-component
Version:
I will import your component, and help to handle it
25 lines (24 loc) • 1.18 kB
JavaScript
import { __assign } from "tslib";
import React, { createContext, useEffect, useState } from 'react';
export var importedState = createContext(undefined);
export var HydrationState = function (_a) {
var state = _a.state, children = _a.children;
return (React.createElement(importedState.Provider, { value: state }, children));
};
/**
* @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
*/
export var ImportedController = function (_a) {
var children = _a.children, _b = _a.usesHydration, usesHydration = _b === void 0 ? true : _b;
var _c = useState({
usesHydration: usesHydration,
pastHydration: false,
}), state = _c[0], setState = _c[1];
useEffect(function () {
setState(function (oldState) { return (__assign(__assign({}, oldState), { pastHydration: true })); });
}, []);
return React.createElement(HydrationState, { state: state }, children);
};