UNPKG

tsx-dom-ssr

Version:

A simple way to use tsx syntax to do async server-side-rendering.

24 lines (23 loc) 862 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createContext = createContext; const internal_1 = require("./internal"); const domUtils_1 = require("./domUtils"); function createContext(options) { const type = Symbol(options.description); return { Provider: (0, internal_1.internalComponent)((props) => (document, thisArg) => (0, domUtils_1.toDom)(document, props.children, { ...thisArg, [type]: props.value, })), for(componentThis) { if (type in componentThis) { return componentThis[type]; } if (options.fallback === undefined) { throw new Error(`Could not find Provider for "${String(type)}" and no fallback was configured!`); } return options.fallback; }, }; }