source: imaps-frontend/node_modules/react-use/esm/factory/createStateContext.js@ d565449

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

Update repo after prototype presentation

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