source: imaps-frontend/node_modules/react-use/lib/factory/createReducerContext.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: 993 bytes
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var createReducerContext = function (reducer, defaultInitialState) {
5 var context = react_1.createContext(undefined);
6 var providerFactory = function (props, children) { return react_1.createElement(context.Provider, props, children); };
7 var ReducerProvider = function (_a) {
8 var children = _a.children, initialState = _a.initialState;
9 var state = react_1.useReducer(reducer, initialState !== undefined ? initialState : defaultInitialState);
10 return providerFactory({ value: state }, children);
11 };
12 var useReducerContext = function () {
13 var state = react_1.useContext(context);
14 if (state == null) {
15 throw new Error("useReducerContext must be used inside a ReducerProvider.");
16 }
17 return state;
18 };
19 return [useReducerContext, ReducerProvider, context];
20};
21exports.default = createReducerContext;
Note: See TracBrowser for help on using the repository browser.