UNPKG

microsite

Version:
14 lines (13 loc) 540 B
import { h, createContext } from "preact"; export const HydrateContext = createContext(false); export const withHydrate = (Component) => { const name = Component.displayName || Component.name; const HydratedComponent = (props) => (h(HydrateContext.Provider, { value: true }, h(Component, Object.assign({}, props)))); HydratedComponent.__withHydrate = true; Object.defineProperty(HydratedComponent, "name", { value: `withHydrate(${name})`, configurable: true, }); return HydratedComponent; };