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
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var react_1 = require("react");
|
---|
4 | var 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 | };
|
---|
21 | exports.default = createReducerContext;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.