import { useState, useEffect } from 'react';
export var useStateValue = function (defaultValue, mergeState, updateWhenDefaultValueChanges, key) {
    if (key === void 0) { key = 'value'; }
    var _a = useState(defaultValue), value = _a[0], setValue = _a[1];
    useEffect(function () {
        var _a;
        if (mergeState) {
            mergeState((_a = {}, _a[key] = defaultValue, _a));
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    useEffect(function () {
        var _a;
        if (updateWhenDefaultValueChanges && mergeState) {
            setValue(defaultValue);
            mergeState((_a = {}, _a[key] = defaultValue, _a));
        }
    }, [defaultValue, updateWhenDefaultValueChanges, mergeState, key]);
    return [value, setValue];
};
