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 12.1.1 to 12.1.2

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [12.1.2](https://github.com/react-hookz/web/compare/v12.1.1...v12.1.2) (2022-01-13)
### Bug Fixes
* move to stricter linting configuration ([#580](https://github.com/react-hookz/web/issues/580)) ([f455992](https://github.com/react-hookz/web/commit/f455992a60b06846fa86a4627d206053b279e96c))
## [12.1.1](https://github.com/react-hookz/web/compare/v12.1.0...v12.1.1) (2022-01-11)

@@ -2,0 +9,0 @@

1

cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.truthyOrArrayPredicate = exports.truthyAndArrayPredicate = exports.useEventListener = exports.useDocumentTitle = exports.useClickOutside = exports.useKeyboardEvent = exports.useMediaQuery = exports.useMeasure = exports.useResizeObserver = exports.useIntersectionObserver = exports.useAsyncAbortable = exports.useAsync = exports.useSessionStorageValue = exports.useLocalStorageValue = exports.useSyncedRef = exports.usePermission = exports.useNetworkState = exports.useValidator = exports.useThrottledState = exports.useToggle = exports.useSet = exports.useSafeState = exports.usePrevious = exports.useMediatedState = exports.useMap = exports.useDebouncedState = exports.useUpdateEffect = exports.useUnmountEffect = exports.useThrottledEffect = exports.useRerender = exports.useMountEffect = exports.useIsomorphicLayoutEffect = exports.useIsMounted = exports.useFirstMountState = exports.useDebouncedEffect = exports.useCustomCompareEffect = exports.useConditionalEffect = exports.useThrottledCallback = exports.useRafCallback = exports.useDebouncedCallback = void 0;
/* eslint-disable import/no-cycle */
// Callback

@@ -5,0 +6,0 @@ var useDebouncedCallback_1 = require("./useDebouncedCallback/useDebouncedCallback");

@@ -42,5 +42,7 @@ "use strict";

setState(function (s) { return (__assign(__assign({}, s), { status: 'loading' })); });
// eslint-disable-next-line promise/catch-or-return
promise.then(function (result) {
// we dont want to handle result/error of non-latest function
// this approach helps to avoid race conditions
// eslint-disable-next-line promise/always-return
if (promise === promiseRef.current) {

@@ -47,0 +49,0 @@ setState(function (s) { return (__assign(__assign({}, s), { status: 'success', error: undefined, result: result })); });

5

cjs/useConditionalEffect/useConditionalEffect.js

@@ -38,6 +38,5 @@ "use strict";

}
effectHook.apply(void 0, __spreadArray([
// eslint-disable-next-line consistent-return
(function () {
effectHook.apply(void 0, __spreadArray([(function () {
if (predicate(conditions)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return callback();

@@ -44,0 +43,0 @@ }

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

exports.useCookieValue = void 0;
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define,no-use-before-define */
var react_1 = require("react");

@@ -63,3 +63,3 @@ var Cookies = require("js-cookie");

if (process.env.NODE_ENV === 'development' && typeof Cookies === 'undefined') {
throw ReferenceError('Dependency `js-cookies` is not installed, it is required for `useCookieValue` work.');
throw new ReferenceError('Dependency `js-cookies` is not installed, it is required for `useCookieValue` work.');
}

@@ -66,0 +66,0 @@ // eslint-disable-next-line prefer-const

@@ -16,2 +16,3 @@ "use strict";

var const_1 = require("../util/const");
// eslint-disable-next-line import/no-cycle
var misc_1 = require("../util/misc");

@@ -18,0 +19,0 @@ /**

@@ -63,5 +63,7 @@ "use strict";

if (!tgt)
return undefined;
return;
var restParams = params.slice(2);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
tgt.addEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return function () { return tgt.removeEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false)); };

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

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

if (!tgt)
return undefined;
return;
var subscribed = true;

@@ -94,0 +94,0 @@ var observerEntry = getObserverEntry({

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

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

@@ -34,2 +34,3 @@ : function (key, defaultValue, options) {

if (const_1.isBrowser && process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('LocalStorage is not available in this environment');

@@ -36,0 +37,0 @@ }

@@ -17,3 +17,7 @@ "use strict";

setState('requested');
navigator.permissions.query(descriptor).then(function (status) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises,promise/catch-or-return
navigator.permissions
.query(descriptor)
// eslint-disable-next-line promise/always-return
.then(function (status) {
var handleChange = function () {

@@ -20,0 +24,0 @@ setState(status.state);

@@ -83,3 +83,2 @@ "use strict";

ro.subscribe(tgt, handler);
// eslint-disable-next-line consistent-return
return function () {

@@ -86,0 +85,0 @@ subscribed = false;

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

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

@@ -34,2 +34,3 @@ : function (key, defaultValue, options) {

if (const_1.isBrowser && process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('SessionStorage is not available in this environment');

@@ -36,0 +37,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useStorageValue = void 0;
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define,no-use-before-define */
var react_1 = require("react");

@@ -80,2 +80,3 @@ var __1 = require("..");

return;
// eslint-disable-next-line unicorn/consistent-function-scoping
var storageHandler = function (ev) {

@@ -89,3 +90,2 @@ if (ev.storageArea !== storage)

(0, misc_1.on)(window, 'storage', storageHandler, { passive: true });
// eslint-disable-next-line consistent-return
return function () {

@@ -112,3 +112,2 @@ (0, misc_1.off)(window, 'storage', storageHandler);

keySetters.add(mSetState);
// eslint-disable-next-line consistent-return
return function () {

@@ -163,12 +162,10 @@ keySetters === null || keySetters === void 0 ? void 0 : keySetters.delete(mSetState);

var newVal = methods.current.fetchState();
if (newVal !== null) {
if (!isolatedRef.current) {
// update all other hooks state
(_b = (_a = storageKeysUsed
.get(storage)) === null || _a === void 0 ? void 0 : _a.get(keyRef.current)) === null || _b === void 0 ? void 0 : _b.forEach(function (setter) {
if (setter === methods.current.setState)
return;
setter(newVal);
});
}
if (newVal !== null && !isolatedRef.current) {
// update all other hooks state
(_b = (_a = storageKeysUsed
.get(storage)) === null || _a === void 0 ? void 0 : _a.get(keyRef.current)) === null || _b === void 0 ? void 0 : _b.forEach(function (setter) {
if (setter === methods.current.setState)
return;
setter(newVal);
});
}

@@ -183,2 +180,3 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

if (data === null) {
// eslint-disable-next-line no-console
console.warn("'null' is not a valid data for useStorageValue hook, this operation will take no effect");

@@ -190,6 +188,7 @@ return null;

}
catch (e) /* istanbul ignore next */ {
catch (error) /* istanbul ignore next */ {
// i have absolutely no idea how to cover this, since modern JSON.stringify does not throw on
// cyclic references anymore
console.warn(e);
// eslint-disable-next-line no-console
console.warn(error);
return null;

@@ -204,6 +203,7 @@ }

}
catch (e) {
console.warn(e);
catch (error) {
// eslint-disable-next-line no-console
console.warn(error);
return fallback;
}
};

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

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

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

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

return wrapped;
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps,@typescript-eslint/no-unsafe-assignment
}, __spreadArray([delay, noTrailing], deps, true));
}
exports.useThrottledCallback = useThrottledCallback;

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

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

@@ -27,0 +27,0 @@ return !prevState;

@@ -24,3 +24,2 @@ "use strict";

exports.off = off;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var hasOwnProperty = function (obj, property) { return Object.prototype.hasOwnProperty.call(obj, property); };

@@ -27,0 +26,0 @@ exports.hasOwnProperty = hasOwnProperty;

@@ -5,2 +5,3 @@ "use strict";

function resolveHookState(nextState, prevState) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
if (typeof nextState === 'function')

@@ -7,0 +8,0 @@ return nextState(prevState);

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

/* eslint-disable import/no-cycle */
// Callback

@@ -2,0 +3,0 @@ export { useDebouncedCallback } from "./useDebouncedCallback/useDebouncedCallback.js";

@@ -39,5 +39,7 @@ var __assign = (this && this.__assign) || function () {

setState(function (s) { return (__assign(__assign({}, s), { status: 'loading' })); });
// eslint-disable-next-line promise/catch-or-return
promise.then(function (result) {
// we dont want to handle result/error of non-latest function
// this approach helps to avoid race conditions
// eslint-disable-next-line promise/always-return
if (promise === promiseRef.current) {

@@ -44,0 +46,0 @@ setState(function (s) { return (__assign(__assign({}, s), { status: 'success', error: undefined, result: result })); });

@@ -35,6 +35,5 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

}
effectHook.apply(void 0, __spreadArray([
// eslint-disable-next-line consistent-return
(function () {
effectHook.apply(void 0, __spreadArray([(function () {
if (predicate(conditions)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return callback();

@@ -41,0 +40,0 @@ }

@@ -12,3 +12,3 @@ var __rest = (this && this.__rest) || function (s, e) {

};
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define,no-use-before-define */
import { useCallback, useEffect } from 'react';

@@ -60,3 +60,3 @@ import * as Cookies from 'js-cookie';

if (process.env.NODE_ENV === 'development' && typeof Cookies === 'undefined') {
throw ReferenceError('Dependency `js-cookies` is not installed, it is required for `useCookieValue` work.');
throw new ReferenceError('Dependency `js-cookies` is not installed, it is required for `useCookieValue` work.');
}

@@ -63,0 +63,0 @@ // eslint-disable-next-line prefer-const

@@ -13,2 +13,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

import { isBrowser } from "../util/const.js";
// eslint-disable-next-line import/no-cycle
import { basicDepsComparator } from "../util/misc.js";

@@ -15,0 +16,0 @@ /**

@@ -60,5 +60,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

if (!tgt)
return undefined;
return;
var restParams = params.slice(2);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
tgt.addEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return function () { return tgt.removeEventListener.apply(tgt, __spreadArray([params[0], eventListener], restParams, false)); };

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

@@ -88,3 +88,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

if (!tgt)
return undefined;
return;
var subscribed = true;

@@ -91,0 +91,0 @@ var observerEntry = getObserverEntry({

@@ -23,3 +23,3 @@ import { useStorageValue, } from "../useStorageValue/useStorageValue.js";

if (options === void 0) { options = {}; }
return useStorageValue(isBrowser ? localStorage : {}, key, defaultValue, options);
return useStorageValue(localStorage, key, defaultValue, options);
}

@@ -31,2 +31,3 @@ : function (key, defaultValue, options) {

if (isBrowser && process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('LocalStorage is not available in this environment');

@@ -33,0 +34,0 @@ }

@@ -14,3 +14,7 @@ import { useEffect } from 'react';

setState('requested');
navigator.permissions.query(descriptor).then(function (status) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises,promise/catch-or-return
navigator.permissions
.query(descriptor)
// eslint-disable-next-line promise/always-return
.then(function (status) {
var handleChange = function () {

@@ -17,0 +21,0 @@ setState(status.state);

@@ -80,3 +80,2 @@ import { useEffect } from 'react';

ro.subscribe(tgt, handler);
// eslint-disable-next-line consistent-return
return function () {

@@ -83,0 +82,0 @@ subscribed = false;

@@ -23,3 +23,3 @@ import { useStorageValue, } from "../useStorageValue/useStorageValue.js";

if (options === void 0) { options = {}; }
return useStorageValue(isBrowser ? sessionStorage : {}, key, defaultValue, options);
return useStorageValue(sessionStorage, key, defaultValue, options);
}

@@ -31,2 +31,3 @@ : function (key, defaultValue, options) {

if (isBrowser && process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('SessionStorage is not available in this environment');

@@ -33,0 +34,0 @@ }

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

/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define,no-use-before-define */
import { useCallback } from 'react';

@@ -77,2 +77,3 @@ import { useConditionalEffect, useFirstMountState, useIsomorphicLayoutEffect, useMountEffect, usePrevious, useSafeState, useSyncedRef, useUpdateEffect, } from '..';

return;
// eslint-disable-next-line unicorn/consistent-function-scoping
var storageHandler = function (ev) {

@@ -86,3 +87,2 @@ if (ev.storageArea !== storage)

on(window, 'storage', storageHandler, { passive: true });
// eslint-disable-next-line consistent-return
return function () {

@@ -109,3 +109,2 @@ off(window, 'storage', storageHandler);

keySetters.add(mSetState);
// eslint-disable-next-line consistent-return
return function () {

@@ -160,12 +159,10 @@ keySetters === null || keySetters === void 0 ? void 0 : keySetters.delete(mSetState);

var newVal = methods.current.fetchState();
if (newVal !== null) {
if (!isolatedRef.current) {
// update all other hooks state
(_b = (_a = storageKeysUsed
.get(storage)) === null || _a === void 0 ? void 0 : _a.get(keyRef.current)) === null || _b === void 0 ? void 0 : _b.forEach(function (setter) {
if (setter === methods.current.setState)
return;
setter(newVal);
});
}
if (newVal !== null && !isolatedRef.current) {
// update all other hooks state
(_b = (_a = storageKeysUsed
.get(storage)) === null || _a === void 0 ? void 0 : _a.get(keyRef.current)) === null || _b === void 0 ? void 0 : _b.forEach(function (setter) {
if (setter === methods.current.setState)
return;
setter(newVal);
});
}

@@ -179,2 +176,3 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

if (data === null) {
// eslint-disable-next-line no-console
console.warn("'null' is not a valid data for useStorageValue hook, this operation will take no effect");

@@ -186,6 +184,7 @@ return null;

}
catch (e) /* istanbul ignore next */ {
catch (error) /* istanbul ignore next */ {
// i have absolutely no idea how to cover this, since modern JSON.stringify does not throw on
// cyclic references anymore
console.warn(e);
// eslint-disable-next-line no-console
console.warn(error);
return null;

@@ -200,6 +199,7 @@ }

}
catch (e) {
console.warn(e);
catch (error) {
// eslint-disable-next-line no-console
console.warn(error);
return fallback;
}
};

@@ -8,8 +8,8 @@ import { useMemo, useRef } from 'react';

export function useSyncedRef(value) {
var _ref = useRef(value);
_ref.current = value;
var ref = useRef(value);
ref.current = value;
return useMemo(function () {
return Object.freeze({
get current() {
return _ref.current;
return ref.current;
},

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

@@ -65,4 +65,4 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

return wrapped;
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps,@typescript-eslint/no-unsafe-assignment
}, __spreadArray([delay, noTrailing], deps, true));
}

@@ -17,7 +17,7 @@ import { useCallback } from 'react';

// toggle logic.
var _a = useSafeState(initialState), state = _a[0], _setState = _a[1];
var _a = useSafeState(initialState), state = _a[0], setState = _a[1];
return [
state,
useCallback(function (nextState) {
_setState(function (prevState) {
setState(function (prevState) {
if (typeof nextState === 'undefined') {

@@ -24,0 +24,0 @@ return !prevState;

@@ -19,3 +19,2 @@ export function on(obj) {

}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export var hasOwnProperty = function (obj, property) { return Object.prototype.hasOwnProperty.call(obj, property); };

@@ -22,0 +21,0 @@ export var yieldTrue = function () { return true; };

export function resolveHookState(nextState, prevState) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
if (typeof nextState === 'function')

@@ -3,0 +4,0 @@ return nextState(prevState);

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

/* eslint-disable import/no-cycle */
// Callback

@@ -2,0 +3,0 @@ export { useDebouncedCallback } from "./useDebouncedCallback/useDebouncedCallback.js";

@@ -24,5 +24,7 @@ import { useMemo, useRef } from 'react';

setState((s) => ({ ...s, status: 'loading' }));
// eslint-disable-next-line promise/catch-or-return
promise.then((result) => {
// we dont want to handle result/error of non-latest function
// this approach helps to avoid race conditions
// eslint-disable-next-line promise/always-return
if (promise === promiseRef.current) {

@@ -29,0 +31,0 @@ setState((s) => ({ ...s, status: 'success', error: undefined, result }));

@@ -20,6 +20,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

export function useConditionalEffect(callback, deps, conditions, predicate = truthyAndArrayPredicate, effectHook = useEffect, ...effectHookRestArgs) {
effectHook(
// eslint-disable-next-line consistent-return
(() => {
effectHook((() => {
if (predicate(conditions)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return callback();

@@ -26,0 +25,0 @@ }

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

/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define,no-use-before-define */
import { useCallback, useEffect } from 'react';

@@ -47,3 +47,3 @@ import * as Cookies from 'js-cookie';

if (process.env.NODE_ENV === 'development' && typeof Cookies === 'undefined') {
throw ReferenceError('Dependency `js-cookies` is not installed, it is required for `useCookieValue` work.');
throw new ReferenceError('Dependency `js-cookies` is not installed, it is required for `useCookieValue` work.');
}

@@ -50,0 +50,0 @@ // eslint-disable-next-line prefer-const

/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useRef } from 'react';
import { isBrowser } from "../util/const.js";
// eslint-disable-next-line import/no-cycle
import { basicDepsComparator } from "../util/misc.js";

@@ -5,0 +6,0 @@ /**

@@ -59,4 +59,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

},
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps,@typescript-eslint/no-unsafe-assignment
[delay, maxWait, ...deps]);
}

@@ -42,5 +42,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

if (!tgt)
return undefined;
return;
const restParams = params.slice(2);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
tgt.addEventListener(params[0], eventListener, ...restParams);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return () => tgt.removeEventListener(params[0], eventListener, ...restParams);

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

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

if (!tgt)
return undefined;
return;
let subscribed = true;

@@ -78,0 +78,0 @@ const observerEntry = getObserverEntry({

@@ -20,6 +20,7 @@ import { useStorageValue, } from "../useStorageValue/useStorageValue.js";

export const useLocalStorageValue = IS_LOCAL_STORAGE_AVAILABLE
? (key, defaultValue = null, options = {}) => useStorageValue(isBrowser ? localStorage : {}, key, defaultValue, options)
? (key, defaultValue = null, options = {}) => useStorageValue(localStorage, key, defaultValue, options)
: (key, defaultValue = null, options = {}) => {
/* istanbul ignore next */
if (isBrowser && process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('LocalStorage is not available in this environment');

@@ -26,0 +27,0 @@ }

@@ -14,3 +14,7 @@ import { useEffect } from 'react';

setState('requested');
navigator.permissions.query(descriptor).then((status) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises,promise/catch-or-return
navigator.permissions
.query(descriptor)
// eslint-disable-next-line promise/always-return
.then((status) => {
const handleChange = () => {

@@ -17,0 +21,0 @@ setState(status.state);

@@ -75,3 +75,2 @@ import { useEffect } from 'react';

ro.subscribe(tgt, handler);
// eslint-disable-next-line consistent-return
return () => {

@@ -78,0 +77,0 @@ subscribed = false;

@@ -20,6 +20,7 @@ import { useStorageValue, } from "../useStorageValue/useStorageValue.js";

export const useSessionStorageValue = IS_SESSION_STORAGE_AVAILABLE
? (key, defaultValue = null, options = {}) => useStorageValue(isBrowser ? sessionStorage : {}, key, defaultValue, options)
? (key, defaultValue = null, options = {}) => useStorageValue(sessionStorage, key, defaultValue, options)
: (key, defaultValue = null, options = {}) => {
/* istanbul ignore next */
if (isBrowser && process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('SessionStorage is not available in this environment');

@@ -26,0 +27,0 @@ }

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

/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define,no-use-before-define */
import { useCallback } from 'react';

@@ -75,2 +75,3 @@ import { useConditionalEffect, useFirstMountState, useIsomorphicLayoutEffect, useMountEffect, usePrevious, useSafeState, useSyncedRef, useUpdateEffect, } from '..';

return;
// eslint-disable-next-line unicorn/consistent-function-scoping
const storageHandler = (ev) => {

@@ -84,3 +85,2 @@ if (ev.storageArea !== storage)

on(window, 'storage', storageHandler, { passive: true });
// eslint-disable-next-line consistent-return
return () => {

@@ -107,3 +107,2 @@ off(window, 'storage', storageHandler);

keySetters.add(mSetState);
// eslint-disable-next-line consistent-return
return () => {

@@ -159,14 +158,12 @@ keySetters?.delete(mSetState);

const newVal = methods.current.fetchState();
if (newVal !== null) {
if (!isolatedRef.current) {
// update all other hooks state
storageKeysUsed
.get(storage)
?.get(keyRef.current)
?.forEach((setter) => {
if (setter === methods.current.setState)
return;
setter(newVal);
});
}
if (newVal !== null && !isolatedRef.current) {
// update all other hooks state
storageKeysUsed
.get(storage)
?.get(keyRef.current)
?.forEach((setter) => {
if (setter === methods.current.setState)
return;
setter(newVal);
});
}

@@ -180,2 +177,3 @@ // eslint-disable-next-line react-hooks/exhaustive-deps

if (data === null) {
// eslint-disable-next-line no-console
console.warn(`'null' is not a valid data for useStorageValue hook, this operation will take no effect`);

@@ -187,6 +185,7 @@ return null;

}
catch (e) /* istanbul ignore next */ {
catch (error) /* istanbul ignore next */ {
// i have absolutely no idea how to cover this, since modern JSON.stringify does not throw on
// cyclic references anymore
console.warn(e);
// eslint-disable-next-line no-console
console.warn(error);
return null;

@@ -201,6 +200,7 @@ }

}
catch (e) {
console.warn(e);
catch (error) {
// eslint-disable-next-line no-console
console.warn(error);
return fallback;
}
};

@@ -8,9 +8,9 @@ import { useMemo, useRef } from 'react';

export function useSyncedRef(value) {
const _ref = useRef(value);
_ref.current = value;
const ref = useRef(value);
ref.current = value;
return useMemo(() => Object.freeze({
get current() {
return _ref.current;
return ref.current;
},
}), []);
}

@@ -51,4 +51,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

return wrapped;
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps,@typescript-eslint/no-unsafe-assignment
}, [delay, noTrailing, ...deps]);
}

@@ -16,7 +16,7 @@ import { useCallback } from 'react';

// toggle logic.
const [state, _setState] = useSafeState(initialState);
const [state, setState] = useSafeState(initialState);
return [
state,
useCallback((nextState) => {
_setState((prevState) => {
setState((prevState) => {
if (typeof nextState === 'undefined') {

@@ -23,0 +23,0 @@ return !prevState;

@@ -11,3 +11,2 @@ export function on(obj, ...args) {

}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const hasOwnProperty = (obj, property) => Object.prototype.hasOwnProperty.call(obj, property);

@@ -14,0 +13,0 @@ export const yieldTrue = () => true;

export function resolveHookState(nextState, prevState) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
if (typeof nextState === 'function')

@@ -3,0 +4,0 @@ return nextState(prevState);

{
"name": "@react-hookz/web",
"version": "12.1.1",
"version": "12.1.2",
"description": "React hooks done right, for browser and SSR.",

@@ -86,12 +86,13 @@ "keywords": [

"@jamesacarr/jest-reporter-github-actions": "^0.0.4",
"@react-hookz/eslint-config": "^1.3.3",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.2",
"@storybook/addon-docs": "^6.4.9",
"@storybook/addon-essentials": "^6.4.10",
"@storybook/addon-links": "^6.4.10",
"@storybook/addons": "^6.4.9",
"@storybook/react": "^6.4.10",
"@storybook/addon-docs": "^6.4.12",
"@storybook/addon-essentials": "^6.4.12",
"@storybook/addon-links": "^6.4.12",
"@storybook/addons": "^6.4.12",
"@storybook/react": "^6.4.12",
"@storybook/storybook-deployer": "^2.8.10",
"@storybook/theming": "^6.4.10",
"@storybook/theming": "^6.4.12",
"@testing-library/react-hooks": "^7.0.2",

@@ -102,4 +103,2 @@ "@types/jest": "^27.4.0",

"@types/react-dom": "^17.0.11",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"babel-loader": "^8.2.3",

@@ -109,12 +108,2 @@ "commitizen": "^4.2.4",

"concurrently": "^7.0.0",
"eslint": "^8.6.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^16.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-mdx": "^1.16.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",

@@ -121,0 +110,0 @@ "husky": "^7.0.4",

@@ -52,7 +52,7 @@ <div align="center">

// in case you need cjs modules
import { useMountEffect } from "@react-hookz/web";
import { useMountEffect } from '@react-hookz/web';
// in case you need esm modules
import { useMountEffect } from "@react-hookz/web/esm";
import { useMountEffect } from '@react-hookz/web/esm';
// in case you want all the recent ES features
import { useMountEffect } from "@react-hookz/web/esnext";
import { useMountEffect } from '@react-hookz/web/esnext';
```

@@ -59,0 +59,0 @@

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