source: imaps-frontend/node_modules/react-use/lib/factory/createStateContext.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 957 bytes
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var createStateContext = function (defaultInitialValue) {
5 var context = react_1.createContext(undefined);
6 var providerFactory = function (props, children) { return react_1.createElement(context.Provider, props, children); };
7 var StateProvider = function (_a) {
8 var children = _a.children, initialValue = _a.initialValue;
9 var state = react_1.useState(initialValue !== undefined ? initialValue : defaultInitialValue);
10 return providerFactory({ value: state }, children);
11 };
12 var useStateContext = function () {
13 var state = react_1.useContext(context);
14 if (state == null) {
15 throw new Error("useStateContext must be used inside a StateProvider.");
16 }
17 return state;
18 };
19 return [useStateContext, StateProvider, context];
20};
21exports.default = createStateContext;
Note: See TracBrowser for help on using the repository browser.