floppy-disk 2.11.1-experimental.2 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +0,0 @@
1
- import { ComponentChildren } from 'preact';
2
- export declare const withContext: <T>(initFn: () => T) => readonly [({ children, onInitialize, }: {
3
- children: ComponentChildren;
4
- onInitialize?: ((value: T) => void) | undefined;
5
- }) => import("preact").VNode<{
6
- value: T | null;
7
- children: ComponentChildren;
8
- }>, () => T | null];
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withContext = void 0;
4
- const preact_1 = require("preact");
5
- const hooks_1 = require("preact/hooks");
6
- const withContext = (initFn) => {
7
- const Context = (0, preact_1.createContext)(null);
8
- const Provider = ({ children, onInitialize, }) => {
9
- const [value] = (0, hooks_1.useState)(() => {
10
- const store = initFn();
11
- onInitialize && onInitialize(store);
12
- return store;
13
- });
14
- return (0, preact_1.createElement)(Context.Provider, { value, children });
15
- };
16
- const useCurrentContext = () => (0, hooks_1.useContext)(Context);
17
- return [Provider, useCurrentContext];
18
- };
19
- exports.withContext = withContext;