@rtbjs/use-state
Version:
`@rtbjs/use-state` is a state management tool that can act as a local state and be easily turned into a global redux state. It is an innovative approach to state management that combines the advantages of both React's useState and Redux's state management
26 lines • 1.14 kB
JavaScript
import { __assign } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useReducer } from 'react';
import { DraggableModalContext } from './DraggableModalContext';
import { getWindowSize } from './getWindowSize';
import { draggableModalReducer, initialModalsState, } from './draggableModalReducer';
export var DraggableModalProvider = function (_a) {
var children = _a.children;
var _b = useReducer(draggableModalReducer, initialModalsState), state = _b[0], dispatch = _b[1];
useEffect(function () {
if (typeof window !== 'object') {
return;
}
var onResize = function () {
return dispatch({ type: 'windowResize', size: getWindowSize() });
};
window.addEventListener('resize', onResize);
onResize();
return function () { return window.removeEventListener('resize', onResize); };
}, [dispatch]);
return (_jsx(DraggableModalContext.Provider, __assign({ value: {
state: state,
dispatch: dispatch
} }, { children: children })));
};
//# sourceMappingURL=DraggableModalProvider.js.map