Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-hookz/web

Package Overview
Dependencies
Maintainers
2
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-hookz/web - npm Package Compare versions

Comparing version 7.0.0 to 8.0.0

13

CHANGELOG.md

@@ -0,1 +1,14 @@

# [8.0.0](https://github.com/react-hookz/web/compare/v7.0.0...v8.0.0) (2021-08-30)
### chore
* **TS:** migrate to TypeScript 4.4 ([#295](https://github.com/react-hookz/web/issues/295)) ([91429f4](https://github.com/react-hookz/web/commit/91429f4723c370c32abc1bb4b6cf4ba72f3918ea))
### BREAKING CHANGES
* **TS:** `IAnyPermissionDescriptor` type removed in favor of
built-in `PermissionDescriptor`.
# [7.0.0](https://github.com/react-hookz/web/compare/v6.1.0...v7.0.0) (2021-08-06)

@@ -2,0 +15,0 @@

2

cjs/index.d.ts

@@ -25,3 +25,3 @@ export { useDebouncedCallback } from './useDebouncedCallback/useDebouncedCallback';

export { useNetworkState, IUseNetworkState, INetworkInformation, } from './useNetworkState/useNetworkState';
export { usePermission, IAnyPermissionDescriptor, IUsePermissionState, } from './usePermission/usePermission';
export { usePermission, IUsePermissionState } from './usePermission/usePermission';
export { useSyncedRef } from './useSyncedRef/useSyncedRef';

@@ -28,0 +28,0 @@ export { useLocalStorageValue } from './useLocalStorageValue/useLocalStorageValue';

@@ -26,3 +26,3 @@ "use strict";

function useAsync(asyncFn, args, options) {
var _a = __1.useSafeState({
var _a = (0, __1.useSafeState)({
status: 'not-executed',

@@ -32,6 +32,6 @@ error: undefined,

}), state = _a[0], setState = _a[1];
var isFirstMount = __1.useFirstMountState();
var promiseRef = react_1.useRef();
var argsRef = react_1.useRef();
var methods = __1.useSyncedRef({
var isFirstMount = (0, __1.useFirstMountState)();
var promiseRef = (0, react_1.useRef)();
var argsRef = (0, react_1.useRef)();
var methods = (0, __1.useSyncedRef)({
execute: function () {

@@ -71,3 +71,3 @@ var params = [];

});
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
var _a;

@@ -81,3 +81,3 @@ if ((isFirstMount && !(options === null || options === void 0 ? void 0 : options.skipMount)) || (!isFirstMount && !(options === null || options === void 0 ? void 0 : options.skipUpdate))) {

state,
react_1.useMemo(function () { return ({
(0, react_1.useMemo)(function () { return ({
reset: function () {

@@ -84,0 +84,0 @@ methods.current.reset();

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -23,5 +27,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

if (events === void 0) { events = DEFAULT_EVENTS; }
var cbRef = __1.useSyncedRef(callback);
var refRef = __1.useSyncedRef(ref);
react_1.useEffect(function () {
var cbRef = (0, __1.useSyncedRef)(callback);
var refRef = (0, __1.useSyncedRef)(ref);
(0, react_1.useEffect)(function () {
function handler(event) {

@@ -36,9 +40,9 @@ if (!refRef.current.current)

}
events.forEach(function (name) { return misc_1.on(document, name, handler, { passive: true }); });
events.forEach(function (name) { return (0, misc_1.on)(document, name, handler, { passive: true }); });
return function () {
events.forEach(function (name) { return misc_1.off(document, name, handler, { passive: true }); });
events.forEach(function (name) { return (0, misc_1.off)(document, name, handler, { passive: true }); });
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, __spreadArray([], events));
}, __spreadArray([], events, true));
}
exports.useClickOutside = useClickOutside;

@@ -20,3 +20,3 @@ "use strict";

// eslint-disable-next-line consistent-return
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
if (predicate(conditions)) {

@@ -23,0 +23,0 @@ return callback();

@@ -19,3 +19,3 @@ "use strict";

// eslint-disable-next-line consistent-return
__1.useUpdateEffect(function () {
(0, __1.useUpdateEffect)(function () {
if (predicate(conditions)) {

@@ -22,0 +22,0 @@ return callback();

@@ -69,3 +69,3 @@ "use strict";

}
var methods = __1.useSyncedRef({
var methods = (0, __1.useSyncedRef)({
set: function (value) {

@@ -89,5 +89,5 @@ setState(value);

});
var isFirstMount = __1.useFirstMountState();
var _b = __1.useSafeState(isFirstMount && initializeWithValue ? methods.current.fetchVal() : undefined), state = _b[0], setState = _b[1];
__1.useMountEffect(function () {
var isFirstMount = (0, __1.useFirstMountState)();
var _b = (0, __1.useSafeState)(isFirstMount && initializeWithValue ? methods.current.fetchVal() : undefined), state = _b[0], setState = _b[1];
(0, __1.useMountEffect)(function () {
if (!initializeWithValue) {

@@ -97,3 +97,3 @@ methods.current.fetch();

});
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
registerSetter(key, setState);

@@ -108,9 +108,9 @@ return function () {

// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useCallback(function (value) { return methods.current.set(value); }, []),
(0, react_1.useCallback)(function (value) { return methods.current.set(value); }, []),
// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useCallback(function () { return methods.current.remove(); }, []),
(0, react_1.useCallback)(function () { return methods.current.remove(); }, []),
// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useCallback(function () { return methods.current.fetch(); }, []),
(0, react_1.useCallback)(function () { return methods.current.fetch(); }, []),
];
}
exports.useCookieValue = useCookieValue;
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -23,5 +27,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

if (maxWait === void 0) { maxWait = 0; }
var timeout = react_1.useRef();
var waitTimeout = react_1.useRef();
var lastCall = react_1.useRef();
var timeout = (0, react_1.useRef)();
var waitTimeout = (0, react_1.useRef)();
var lastCall = (0, react_1.useRef)();
var clear = function () {

@@ -38,4 +42,4 @@ if (timeout.current) {

// cancel scheduled execution on unmount
useUnmountEffect_1.useUnmountEffect(clear);
return react_1.useMemo(function () {
(0, useUnmountEffect_1.useUnmountEffect)(clear);
return (0, react_1.useMemo)(function () {
var execute = function () {

@@ -73,4 +77,4 @@ // barely possible to test this line

return wrapped;
}, __spreadArray([delay, maxWait], deps));
}, __spreadArray([delay, maxWait], deps, true));
}
exports.useDebouncedCallback = useDebouncedCallback;

@@ -21,4 +21,4 @@ "use strict";

// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useEffect(__1.useDebouncedCallback(callback, deps, delay, maxWait), deps);
(0, react_1.useEffect)((0, __1.useDebouncedCallback)(callback, deps, delay, maxWait), deps);
}
exports.useDebouncedEffect = useDebouncedEffect;

@@ -15,5 +15,5 @@ "use strict";

if (maxWait === void 0) { maxWait = 0; }
var _a = __1.useSafeState(initialState), state = _a[0], setState = _a[1];
return [state, __1.useDebouncedCallback(setState, [], delay, maxWait)];
var _a = (0, __1.useSafeState)(initialState), state = _a[0], setState = _a[1];
return [state, (0, __1.useDebouncedCallback)(setState, [], delay, maxWait)];
}
exports.useDebouncedState = useDebouncedState;

@@ -15,10 +15,10 @@ "use strict";

if (options === void 0) { options = {}; }
var titleRef = react_1.useRef(const_1.isBrowser ? document.title : '');
var optionsRef = __1.useSyncedRef(options);
var titleRef = (0, react_1.useRef)(const_1.isBrowser ? document.title : '');
var optionsRef = (0, __1.useSyncedRef)(options);
// it is safe not to check isBrowser here, as effects are not invoked in SSR
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
document.title = options.wrapper ? options.wrapper(title) : title;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [title, options.wrapper]);
__1.useUnmountEffect(function () {
(0, __1.useUnmountEffect)(function () {
if (optionsRef.current.restoreOnUnmount) {

@@ -25,0 +25,0 @@ document.title = titleRef.current;

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -26,6 +30,6 @@ Object.defineProperty(exports, "__esModule", { value: true });

}
var isMounted = __1.useIsMounted();
var isMounted = (0, __1.useIsMounted)();
// create static event listener
var listenerRef = __1.useSyncedRef(params[1]);
var eventListener = react_1.useMemo(function () {
var listenerRef = (0, __1.useSyncedRef)(params[1]);
var eventListener = (0, react_1.useMemo)(function () {
// as some event listeners designed to be used through `this`

@@ -57,9 +61,9 @@ // it is better to make listener a conventional function as it

[]);
react_1.useEffect(function () {
var tgt = target && misc_1.hasOwnProperty(target, 'current') ? target.current : target;
(0, react_1.useEffect)(function () {
var tgt = target && (0, misc_1.hasOwnProperty)(target, 'current') ? target.current : target;
if (!tgt)
return undefined;
var restParams = params.slice(2);
tgt.addEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams));
return function () { return tgt.removeEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams)); };
tgt.addEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false));
return function () { return tgt.removeEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false)); };
// eslint-disable-next-line react-hooks/exhaustive-deps

@@ -66,0 +70,0 @@ }, [target, params[0]]);

@@ -9,4 +9,4 @@ "use strict";

function useFirstMountState() {
var isFirstMount = react_1.useRef(true);
react_1.useEffect(function () {
var isFirstMount = (0, react_1.useRef)(true);
(0, react_1.useEffect)(function () {
isFirstMount.current = false;

@@ -13,0 +13,0 @@ }, []);

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -83,4 +87,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

var _b = _a === void 0 ? {} : _a, _c = _b.threshold, threshold = _c === void 0 ? DEFAULT_THRESHOLD : _c, r = _b.root, _d = _b.rootMargin, rootMargin = _d === void 0 ? DEFAULT_ROOT_MARGIN : _d;
var _e = __1.useSafeState(), state = _e[0], setState = _e[1];
react_1.useEffect(function () {
var _e = (0, __1.useSafeState)(), state = _e[0], setState = _e[1];
(0, react_1.useEffect)(function () {
var tgt = target && 'current' in target ? target.current : target;

@@ -109,5 +113,5 @@ if (!tgt)

// eslint-disable-next-line react-hooks/exhaustive-deps
}, __spreadArray([target, r, rootMargin], threshold));
}, __spreadArray([target, r, rootMargin], threshold, true));
return state;
}
exports.useIntersectionObserver = useIntersectionObserver;

@@ -13,5 +13,5 @@ "use strict";

function useIsMounted() {
var isMounted = react_1.useRef(false);
var get = react_1.useCallback(function () { return isMounted.current; }, []);
react_1.useEffect(function () {
var isMounted = (0, react_1.useRef)(false);
var get = (0, react_1.useCallback)(function () { return isMounted.current; }, []);
(0, react_1.useEffect)(function () {
isMounted.current = true;

@@ -18,0 +18,0 @@ return function () {

@@ -27,4 +27,4 @@ "use strict";

var _a = options.event, event = _a === void 0 ? 'keydown' : _a, _b = options.target, target = _b === void 0 ? WINDOW_OR_NULL : _b, eventOptions = options.eventOptions;
var cbRef = __1.useSyncedRef(callback);
var handler = react_1.useMemo(function () {
var cbRef = (0, __1.useSyncedRef)(callback);
var handler = (0, react_1.useMemo)(function () {
var predicate = createKeyPredicate(keyOrPredicate);

@@ -38,4 +38,4 @@ return function kbEventHandler(ev) {

}, deps);
__1.useEventListener(target, event, handler, eventOptions);
(0, __1.useEventListener)(target, event, handler, eventOptions);
}
exports.useKeyboardEvent = useKeyboardEvent;

@@ -16,4 +16,4 @@ "use strict";

if (options === void 0) { options = {}; }
return useStorageValue_1.useStorageValue(const_1.isBrowser ? localStorage : {}, key, defaultValue, options);
return (0, useStorageValue_1.useStorageValue)(const_1.isBrowser ? localStorage : {}, key, defaultValue, options);
}
exports.useLocalStorageValue = useLocalStorageValue;

@@ -14,4 +14,4 @@ "use strict";

function useMap(entries) {
var mapRef = react_1.useRef();
var rerender = __1.useRerender();
var mapRef = (0, react_1.useRef)();
var rerender = (0, __1.useRerender)();
if (!mapRef.current) {

@@ -18,0 +18,0 @@ var map_1 = new Map(entries);

@@ -10,10 +10,10 @@ "use strict";

function useMeasure() {
var elementRef = react_1.useRef(null);
var _a = __1.useSafeState(), rect = _a[0], setRect = _a[1];
var observerHandler = __1.useRafCallback(function (entry) {
var elementRef = (0, react_1.useRef)(null);
var _a = (0, __1.useSafeState)(), rect = _a[0], setRect = _a[1];
var observerHandler = (0, __1.useRafCallback)(function (entry) {
return setRect(entry.contentRect);
})[0];
__1.useResizeObserver(elementRef, observerHandler);
(0, __1.useResizeObserver)(elementRef, observerHandler);
return [rect, elementRef];
}
exports.useMeasure = useMeasure;

@@ -53,4 +53,4 @@ "use strict";

function useMediaQuery(query) {
var _a = __1.useSafeState(), state = _a[0], setState = _a[1];
react_1.useEffect(function () {
var _a = (0, __1.useSafeState)(), state = _a[0], setState = _a[1];
(0, react_1.useEffect)(function () {
querySubscribe(query, setState);

@@ -57,0 +57,0 @@ return function () {

@@ -11,9 +11,9 @@ "use strict";

function useMediatedState(initialState, mediator) {
var _a = __1.useSafeState(initialState), state = _a[0], setState = _a[1];
var mediatorRef = __1.useSyncedRef(mediator);
var _a = (0, __1.useSafeState)(initialState), state = _a[0], setState = _a[1];
var mediatorRef = (0, __1.useSyncedRef)(mediator);
return [
state,
react_1.useCallback(function (value) {
(0, react_1.useCallback)(function (value) {
if (mediatorRef.current) {
setState(function (prevState) { var _a; return (_a = mediatorRef.current) === null || _a === void 0 ? void 0 : _a.call(mediatorRef, resolveHookState_1.resolveHookState(value, prevState)); });
setState(function (prevState) { var _a; return (_a = mediatorRef.current) === null || _a === void 0 ? void 0 : _a.call(mediatorRef, (0, resolveHookState_1.resolveHookState)(value, prevState)); });
}

@@ -20,0 +20,0 @@ else {

@@ -11,3 +11,3 @@ "use strict";

function useMountEffect(effect) {
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
effect();

@@ -14,0 +14,0 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

@@ -29,20 +29,20 @@ "use strict";

function useNetworkState(initialState) {
var _a = __1.useSafeState(initialState !== null && initialState !== void 0 ? initialState : getConnectionState), state = _a[0], setState = _a[1];
react_1.useEffect(function () {
var _a = (0, __1.useSafeState)(initialState !== null && initialState !== void 0 ? initialState : getConnectionState), state = _a[0], setState = _a[1];
(0, react_1.useEffect)(function () {
var handleStateChange = function () {
setState(getConnectionState);
};
misc_1.on(window, 'online', handleStateChange, { passive: true });
misc_1.on(window, 'offline', handleStateChange, { passive: true });
(0, misc_1.on)(window, 'online', handleStateChange, { passive: true });
(0, misc_1.on)(window, 'offline', handleStateChange, { passive: true });
// it is quite hard to test it in jsdom environment maybe will be improved in future
/* istanbul ignore next */
if (conn) {
misc_1.on(conn, 'change', handleStateChange, { passive: true });
(0, misc_1.on)(conn, 'change', handleStateChange, { passive: true });
}
return function () {
misc_1.off(window, 'online', handleStateChange);
misc_1.off(window, 'offline', handleStateChange);
(0, misc_1.off)(window, 'online', handleStateChange);
(0, misc_1.off)(window, 'offline', handleStateChange);
/* istanbul ignore next */
if (conn) {
misc_1.off(conn, 'change', handleStateChange);
(0, misc_1.off)(conn, 'change', handleStateChange);
}

@@ -49,0 +49,0 @@ };

@@ -1,2 +0,1 @@

export declare type IAnyPermissionDescriptor = PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor;
export declare type IUsePermissionState = PermissionState | 'not-requested' | 'requested';

@@ -8,2 +7,2 @@ /**

*/
export declare function usePermission(descriptor: IAnyPermissionDescriptor): IUsePermissionState;
export declare function usePermission(descriptor: PermissionDescriptor): IUsePermissionState;

@@ -13,4 +13,4 @@ "use strict";

function usePermission(descriptor) {
var _a = __1.useSafeState('not-requested'), state = _a[0], setState = _a[1];
react_1.useEffect(function () {
var _a = (0, __1.useSafeState)('not-requested'), state = _a[0], setState = _a[1];
(0, react_1.useEffect)(function () {
var unmount = { current: null };

@@ -23,5 +23,5 @@ setState('requested');

setState(status.state);
misc_1.on(status, 'change', handleChange, { passive: true });
(0, misc_1.on)(status, 'change', handleChange, { passive: true });
unmount.current = function () {
misc_1.off(status, 'change', handleChange);
(0, misc_1.off)(status, 'change', handleChange);
};

@@ -28,0 +28,0 @@ });

@@ -13,4 +13,4 @@ "use strict";

function usePrevious(value) {
var prev = react_1.useRef();
react_1.useEffect(function () {
var prev = (0, react_1.useRef)();
(0, react_1.useEffect)(function () {
prev.current = value;

@@ -17,0 +17,0 @@ });

@@ -16,5 +16,5 @@ "use strict";

function useRafCallback(cb) {
var cbRef = __1.useSyncedRef(cb);
var frame = react_1.useRef(0);
var cancel = react_1.useCallback(function () {
var cbRef = (0, __1.useSyncedRef)(cb);
var frame = (0, react_1.useRef)(0);
var cancel = (0, react_1.useCallback)(function () {
if (!const_1.isBrowser)

@@ -27,5 +27,5 @@ return;

}, []);
__1.useUnmountEffect(cancel);
(0, __1.useUnmountEffect)(cancel);
return [
react_1.useMemo(function () {
(0, react_1.useMemo)(function () {
var wrapped = function () {

@@ -32,0 +32,0 @@ var args = [];

@@ -11,4 +11,4 @@ "use strict";

function useRerender() {
var _a = __1.useSafeState(false), setState = _a[1];
return react_1.useCallback(function () {
var _a = (0, __1.useSafeState)(false), setState = _a[1];
return (0, react_1.useCallback)(function () {
setState(stateChanger);

@@ -15,0 +15,0 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

@@ -57,4 +57,4 @@ "use strict";

var ro = getResizeObserver();
var cb = __1.useSyncedRef(callback);
react_1.useEffect(function () {
var cb = (0, __1.useSyncedRef)(callback);
(0, react_1.useEffect)(function () {
// quite difficult to cover with tests, but the 'if' branch is pretty

@@ -61,0 +61,0 @@ // straightforward: do nothing, it is safe to exclude from LOC

@@ -10,7 +10,7 @@ "use strict";

function useSafeState(initialState) {
var _a = react_1.useState(initialState), state = _a[0], setState = _a[1];
var isMounted = __1.useIsMounted();
var _a = (0, react_1.useState)(initialState), state = _a[0], setState = _a[1];
var isMounted = (0, __1.useIsMounted)();
return [
state,
react_1.useCallback(function (value) {
(0, react_1.useCallback)(function (value) {
if (isMounted())

@@ -17,0 +17,0 @@ setState(value);

@@ -16,4 +16,4 @@ "use strict";

if (options === void 0) { options = {}; }
return useStorageValue_1.useStorageValue(const_1.isBrowser ? sessionStorage : {}, key, defaultValue, options);
return (0, useStorageValue_1.useStorageValue)(const_1.isBrowser ? sessionStorage : {}, key, defaultValue, options);
}
exports.useSessionStorageValue = useSessionStorageValue;

@@ -14,4 +14,4 @@ "use strict";

function useSet(values) {
var setRef = react_1.useRef();
var rerender = __1.useRerender();
var setRef = (0, react_1.useRef)();
var rerender = (0, __1.useRerender)();
if (!setRef.current) {

@@ -18,0 +18,0 @@ var set_1 = new Set(values);

@@ -30,3 +30,3 @@ "use strict";

// needed to provide stable API
var methods = __1.useSyncedRef({
var methods = (0, __1.useSyncedRef)({
fetchVal: function () { return parse(storage.getItem(key), defaultValue); },

@@ -56,11 +56,11 @@ storeVal: function (val) {

});
var isFirstMount = __1.useFirstMountState();
var _c = __1.useSafeState(initializeWithStorageValue && isFirstMount ? methods.current.fetchVal() : undefined), state = _c[0], setState = _c[1];
var prevState = __1.usePrevious(state);
var stateRef = __1.useSyncedRef(state);
var keyRef = __1.useSyncedRef(key);
var isolatedRef = __1.useSyncedRef(isolated);
var isFirstMount = (0, __1.useFirstMountState)();
var _c = (0, __1.useSafeState)(initializeWithStorageValue && isFirstMount ? methods.current.fetchVal() : undefined), state = _c[0], setState = _c[1];
var prevState = (0, __1.usePrevious)(state);
var stateRef = (0, __1.useSyncedRef)(state);
var keyRef = (0, __1.useSyncedRef)(key);
var isolatedRef = (0, __1.useSyncedRef)(isolated);
// fetch value on mount for the case `initializeWithStorageValue` is false,
// effects are not invoked during SSR, so there is no need to check isBrowser here
__1.useMountEffect(function () {
(0, __1.useMountEffect)(function () {
if (!initializeWithStorageValue) {

@@ -71,13 +71,13 @@ methods.current.fetchState();

// store default value if it is not null and options configured to store default value
__1.useConditionalEffect(function () {
(0, __1.useConditionalEffect)(function () {
methods.current.storeVal(defaultValue);
}, [prevState !== state, state === defaultValue && defaultValue !== null && storeDefaultValue]);
// refetch value when key changed
__1.useUpdateEffect(function () {
(0, __1.useUpdateEffect)(function () {
methods.current.fetchState();
}, [key]);
// register hook for same-page synchronisation
react_1.useEffect(function () { }, [key]);
(0, react_1.useEffect)(function () { }, [key]);
// subscribe hook for storage events
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
if (!handleStorageEvent)

@@ -92,10 +92,10 @@ return;

};
misc_1.on(window, 'storage', storageHandler, { passive: true });
(0, misc_1.on)(window, 'storage', storageHandler, { passive: true });
// eslint-disable-next-line consistent-return
return function () {
misc_1.off(window, 'storage', storageHandler);
(0, misc_1.off)(window, 'storage', storageHandler);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [handleStorageEvent]);
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
if (isolated)

@@ -123,7 +123,7 @@ return;

state,
react_1.useCallback(function (newState) {
(0, react_1.useCallback)(function (newState) {
var _a, _b;
if (!const_1.isBrowser)
return;
var s = resolveHookState_1.resolveHookState(newState, stateRef.current);
var s = (0, resolveHookState_1.resolveHookState)(newState, stateRef.current);
if (methods.current.storeVal(s)) {

@@ -143,3 +143,3 @@ methods.current.setState(s);

[]),
react_1.useCallback(function () {
(0, react_1.useCallback)(function () {
var _a, _b;

@@ -161,3 +161,3 @@ if (!const_1.isBrowser)

}, []),
react_1.useCallback(function () {
(0, react_1.useCallback)(function () {
var _a, _b;

@@ -164,0 +164,0 @@ if (!const_1.isBrowser)

@@ -11,5 +11,5 @@ "use strict";

function useSyncedRef(value) {
var _ref = react_1.useRef(value);
var _ref = (0, react_1.useRef)(value);
_ref.current = value;
return react_1.useMemo(function () {
return (0, react_1.useMemo)(function () {
return Object.freeze({

@@ -16,0 +16,0 @@ get current() {

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -24,5 +28,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

if (noTrailing === void 0) { noTrailing = false; }
var timeout = react_1.useRef();
var lastCall = react_1.useRef();
__1.useUnmountEffect(function () {
var timeout = (0, react_1.useRef)();
var lastCall = (0, react_1.useRef)();
(0, __1.useUnmountEffect)(function () {
if (timeout.current) {

@@ -32,3 +36,3 @@ clearTimeout(timeout.current);

});
return react_1.useMemo(function () {
return (0, react_1.useMemo)(function () {
var execute = function (context, args) {

@@ -67,4 +71,4 @@ lastCall.current = undefined;

// eslint-disable-next-line react-hooks/exhaustive-deps
}, __spreadArray([delay, noTrailing], deps));
}, __spreadArray([delay, noTrailing], deps, true));
}
exports.useThrottledCallback = useThrottledCallback;

@@ -22,4 +22,4 @@ "use strict";

// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useEffect(__1.useThrottledCallback(callback, deps, delay, noTrailing), deps);
(0, react_1.useEffect)((0, __1.useThrottledCallback)(callback, deps, delay, noTrailing), deps);
}
exports.useThrottledEffect = useThrottledEffect;

@@ -16,5 +16,5 @@ "use strict";

if (noTrailing === void 0) { noTrailing = false; }
var _a = __1.useSafeState(initialState), state = _a[0], setState = _a[1];
return [state, __1.useThrottledCallback(setState, [], delay, noTrailing)];
var _a = (0, __1.useSafeState)(initialState), state = _a[0], setState = _a[1];
return [state, (0, __1.useThrottledCallback)(setState, [], delay, noTrailing)];
}
exports.useThrottledState = useThrottledState;

@@ -20,6 +20,6 @@ "use strict";

// toggle logic.
var _a = __1.useSafeState(initialState), state = _a[0], _setState = _a[1];
var _a = (0, __1.useSafeState)(initialState), state = _a[0], _setState = _a[1];
return [
state,
react_1.useCallback(function (nextState) {
(0, react_1.useCallback)(function (nextState) {
_setState(function (prevState) {

@@ -29,3 +29,3 @@ if (typeof nextState === 'undefined') {

}
return Boolean(resolveHookState_1.resolveHookState(nextState, prevState));
return Boolean((0, resolveHookState_1.resolveHookState)(nextState, prevState));
});

@@ -32,0 +32,0 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

@@ -11,3 +11,3 @@ "use strict";

function useUnmountEffect(effect) {
react_1.useEffect(function () { return function () {
(0, react_1.useEffect)(function () { return function () {
effect();

@@ -14,0 +14,0 @@ }; },

@@ -14,6 +14,6 @@ "use strict";

function useUpdateEffect(effect, deps) {
var isFirstMount = __1.useFirstMountState();
var isFirstMount = (0, __1.useFirstMountState)();
// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useEffect(isFirstMount ? const_1.noop : effect, deps);
(0, react_1.useEffect)(isFirstMount ? const_1.noop : effect, deps);
}
exports.useUpdateEffect = useUpdateEffect;

@@ -15,4 +15,4 @@ "use strict";

if (initialValidity === void 0) { initialValidity = { isValid: undefined }; }
var _a = __1.useSafeState(initialValidity), validity = _a[0], setValidity = _a[1];
var validatorRef = __1.useSyncedRef(function () {
var _a = (0, __1.useSafeState)(initialValidity), validity = _a[0], setValidity = _a[1];
var validatorRef = (0, __1.useSyncedRef)(function () {
if (validator.length) {

@@ -25,3 +25,3 @@ validator(setValidity);

});
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
validatorRef.current();

@@ -32,3 +32,3 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

validity,
react_1.useCallback(function () {
(0, react_1.useCallback)(function () {
validatorRef.current();

@@ -35,0 +35,0 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

@@ -25,3 +25,3 @@ export { useDebouncedCallback } from './useDebouncedCallback/useDebouncedCallback';

export { useNetworkState, IUseNetworkState, INetworkInformation, } from './useNetworkState/useNetworkState';
export { usePermission, IAnyPermissionDescriptor, IUsePermissionState, } from './usePermission/usePermission';
export { usePermission, IUsePermissionState } from './usePermission/usePermission';
export { useSyncedRef } from './useSyncedRef/useSyncedRef';

@@ -28,0 +28,0 @@ export { useLocalStorageValue } from './useLocalStorageValue/useLocalStorageValue';

@@ -29,3 +29,3 @@ // Callback

export { useNetworkState, } from "./useNetworkState/useNetworkState.js";
export { usePermission, } from "./usePermission/usePermission.js";
export { usePermission } from "./usePermission/usePermission.js";
// Miscellaneous

@@ -32,0 +32,0 @@ export { useSyncedRef } from "./useSyncedRef/useSyncedRef.js";

@@ -1,5 +0,9 @@

var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -37,3 +41,3 @@ import { useEffect } from 'react';

// eslint-disable-next-line react-hooks/exhaustive-deps
}, __spreadArray([], events));
}, __spreadArray([], events, true));
}

@@ -1,5 +0,9 @@

var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -68,3 +72,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

return wrapped;
}, __spreadArray([delay, maxWait], deps));
}, __spreadArray([delay, maxWait], deps, true));
}

@@ -1,5 +0,9 @@

var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -58,6 +62,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

var restParams = params.slice(2);
tgt.addEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams));
return function () { return tgt.removeEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams)); };
tgt.addEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false));
return function () { return tgt.removeEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false)); };
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [target, params[0]]);
}

@@ -1,5 +0,9 @@

var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -105,4 +109,4 @@ import { useEffect } from 'react';

// eslint-disable-next-line react-hooks/exhaustive-deps
}, __spreadArray([target, r, rootMargin], threshold));
}, __spreadArray([target, r, rootMargin], threshold, true));
return state;
}

@@ -1,2 +0,1 @@

export declare type IAnyPermissionDescriptor = PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor;
export declare type IUsePermissionState = PermissionState | 'not-requested' | 'requested';

@@ -8,2 +7,2 @@ /**

*/
export declare function usePermission(descriptor: IAnyPermissionDescriptor): IUsePermissionState;
export declare function usePermission(descriptor: PermissionDescriptor): IUsePermissionState;

@@ -1,5 +0,9 @@

var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -62,3 +66,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

// eslint-disable-next-line react-hooks/exhaustive-deps
}, __spreadArray([delay, noTrailing], deps));
}, __spreadArray([delay, noTrailing], deps, true));
}

@@ -25,3 +25,3 @@ export { useDebouncedCallback } from './useDebouncedCallback/useDebouncedCallback';

export { useNetworkState, IUseNetworkState, INetworkInformation, } from './useNetworkState/useNetworkState';
export { usePermission, IAnyPermissionDescriptor, IUsePermissionState, } from './usePermission/usePermission';
export { usePermission, IUsePermissionState } from './usePermission/usePermission';
export { useSyncedRef } from './useSyncedRef/useSyncedRef';

@@ -28,0 +28,0 @@ export { useLocalStorageValue } from './useLocalStorageValue/useLocalStorageValue';

@@ -29,3 +29,3 @@ // Callback

export { useNetworkState, } from "./useNetworkState/useNetworkState.js";
export { usePermission, } from "./usePermission/usePermission.js";
export { usePermission } from "./usePermission/usePermission.js";
// Miscellaneous

@@ -32,0 +32,0 @@ export { useSyncedRef } from "./useSyncedRef/useSyncedRef.js";

@@ -1,2 +0,1 @@

export declare type IAnyPermissionDescriptor = PermissionDescriptor | DevicePermissionDescriptor | MidiPermissionDescriptor | PushPermissionDescriptor;
export declare type IUsePermissionState = PermissionState | 'not-requested' | 'requested';

@@ -8,2 +7,2 @@ /**

*/
export declare function usePermission(descriptor: IAnyPermissionDescriptor): IUsePermissionState;
export declare function usePermission(descriptor: PermissionDescriptor): IUsePermissionState;
{
"name": "@react-hookz/web",
"version": "7.0.0",
"version": "8.0.0",
"description": "React hooks done right, for browser and SSR.",

@@ -70,3 +70,3 @@ "keywords": [

"@types/js-cookie": "^2.2.7",
"@types/react": "^17.0.15",
"@types/react": "^17.0.19",
"@types/react-dom": "^17.0.9"

@@ -95,32 +95,32 @@ },

"@storybook/addon-docs": "^6.3.6",
"@storybook/addon-essentials": "^6.3.6",
"@storybook/addon-links": "^6.3.6",
"@storybook/addon-essentials": "^6.3.7",
"@storybook/addon-links": "^6.3.7",
"@storybook/addons": "^6.3.4",
"@storybook/react": "^6.3.6",
"@storybook/react": "^6.3.7",
"@storybook/storybook-deployer": "^2.8.10",
"@storybook/theming": "^6.3.6",
"@storybook/theming": "^6.3.7",
"@testing-library/react-hooks": "^7.0.1",
"@types/jest": "^26.0.24",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"babel-loader": "^8.2.2",
"commitizen": "^4.2.4",
"commitlint": "^13.1.0",
"concurrently": "^6.2.0",
"concurrently": "^6.2.1",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-airbnb-typescript": "^14.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-mdx": "^1.14.1",
"eslint-plugin-mdx": "^1.15.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-react": "^7.25.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"husky": "^7.0.2",
"jest": "^27.1.0",
"jest-github-actions-reporter": "^1.0.3",
"js-cookie": "^3.0.0",
"lint-staged": "^11.1.1",
"lint-staged": "^11.1.2",
"prettier": "^2.3.2",

@@ -130,5 +130,5 @@ "react": "^17.0.2",

"rimraf": "^3.0.2",
"semantic-release": "^17.4.4",
"ts-jest": "^27.0.4",
"ts-node": "^10.1.0",
"semantic-release": "^17.4.7",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"ttypescript": "^1.5.12",

@@ -135,0 +135,0 @@ "typescript": "^4.3.5",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc