source: imaps-frontend/node_modules/react-use/lib/useGetSetState.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: 1.1 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useUpdate_1 = tslib_1.__importDefault(require("./useUpdate"));
6var useGetSetState = function (initialState) {
7 if (initialState === void 0) { initialState = {}; }
8 if (process.env.NODE_ENV !== 'production') {
9 if (typeof initialState !== 'object') {
10 console.error('useGetSetState initial state must be an object.');
11 }
12 }
13 var update = useUpdate_1.default();
14 var state = react_1.useRef(tslib_1.__assign({}, initialState));
15 var get = react_1.useCallback(function () { return state.current; }, []);
16 var set = react_1.useCallback(function (patch) {
17 if (!patch) {
18 return;
19 }
20 if (process.env.NODE_ENV !== 'production') {
21 if (typeof patch !== 'object') {
22 console.error('useGetSetState setter patch must be an object.');
23 }
24 }
25 Object.assign(state.current, patch);
26 update();
27 }, []);
28 return [get, set];
29};
30exports.default = useGetSetState;
Note: See TracBrowser for help on using the repository browser.