UNPKG

540 BJavaScriptView Raw
1import { h, createContext } from "preact";
2export const HydrateContext = createContext(false);
3export const withHydrate = (Component) => {
4 const name = Component.displayName || Component.name;
5 const HydratedComponent = (props) => (h(HydrateContext.Provider, { value: true },
6 h(Component, Object.assign({}, props))));
7 HydratedComponent.__withHydrate = true;
8 Object.defineProperty(HydratedComponent, "name", {
9 value: `withHydrate(${name})`,
10 configurable: true,
11 });
12 return HydratedComponent;
13};