state-pool
Version:
Transform your React app with our state management library! Declare global and local states like variables, powered by the magic of React hooks 🪄✨
19 lines (18 loc) • 760 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var useReducer_1 = __importDefault(require("./useReducer"));
function useState(state, config) {
if (config === void 0) { config = {}; }
function reducer(currentState, newState) {
return newState;
}
var _a = (0, useReducer_1.default)(reducer, state, config), stateValue = _a[0], setStateValue = _a[1], stateObject = _a[2];
function updateStateValue(updater) {
stateObject.updateValue(updater, config);
}
return [stateValue, setStateValue, updateStateValue, stateObject];
}
exports.default = useState;