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 3.8.0 to 4.0.0

13

CHANGELOG.md

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

# [4.0.0](https://github.com/react-hookz/web/compare/v3.8.0...v4.0.0) (2021-07-16)
### Features
* deps for `useConditionalUpdateEffect` and `useConditionalEffect` ([#201](https://github.com/react-hookz/web/issues/201)) ([bd56af3](https://github.com/react-hookz/web/commit/bd56af3c775123450867931aa07a33eaf08415e7))
### BREAKING CHANGES
* `useConditionalUpdateEffect` and `useConditionalEffect`
now has changed call signature (new argument).
# [3.8.0](https://github.com/react-hookz/web/compare/v3.7.0...v3.8.0) (2021-07-03)

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

1

cjs/index.d.ts

@@ -38,1 +38,2 @@ export { useDebouncedCallback } from './useDebouncedCallback/useDebouncedCallback';

export { useEventListener } from './useEventListener/useEventListener';
export { truthyAndArrayPredicate, truthyOrArrayPredicate } from './util/const';

5

cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useEventListener = exports.useDocumentTitle = exports.useClickOutside = exports.useMediaQuery = exports.useMeasure = exports.useResizeObserver = exports.useIntersectionObserver = exports.useAsync = exports.useCookieValue = 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.useConditionalUpdateEffect = exports.useConditionalEffect = exports.useThrottledCallback = exports.useRafCallback = exports.useDebouncedCallback = void 0;
exports.truthyOrArrayPredicate = exports.truthyAndArrayPredicate = exports.useEventListener = exports.useDocumentTitle = exports.useClickOutside = exports.useMediaQuery = exports.useMeasure = exports.useResizeObserver = exports.useIntersectionObserver = exports.useAsync = exports.useCookieValue = 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.useConditionalUpdateEffect = exports.useConditionalEffect = exports.useThrottledCallback = exports.useRafCallback = exports.useDebouncedCallback = void 0;
// Callback

@@ -86,1 +86,4 @@ var useDebouncedCallback_1 = require("./useDebouncedCallback/useDebouncedCallback");

Object.defineProperty(exports, "useEventListener", { enumerable: true, get: function () { return useEventListener_1.useEventListener; } });
var const_1 = require("./util/const");
Object.defineProperty(exports, "truthyAndArrayPredicate", { enumerable: true, get: function () { return const_1.truthyAndArrayPredicate; } });
Object.defineProperty(exports, "truthyOrArrayPredicate", { enumerable: true, get: function () { return const_1.truthyOrArrayPredicate; } });

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

import { EffectCallback } from 'react';
import { DependencyList, EffectCallback } from 'react';
export declare type IUseConditionalEffectPredicate<Cond extends ReadonlyArray<any>> = (conditions: Cond) => boolean;

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

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,2 +15,2 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
export declare function useConditionalEffect<T extends ReadonlyArray<any>>(callback: EffectCallback, conditions: T, predicate?: IUseConditionalEffectPredicate<T>): void;
export declare function useConditionalEffect<T extends ReadonlyArray<unknown>>(callback: EffectCallback, conditions: T, deps?: DependencyList, predicate?: IUseConditionalEffectPredicate<T>): void;

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

var react_1 = require("react");
var const_1 = require("../util/const");
var __1 = require("..");
/**

@@ -12,2 +12,4 @@ * Like `useEffect` but callback invoked only if conditions match predicate.

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -17,16 +19,12 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function useConditionalEffect(callback, conditions, predicate) {
if (predicate === void 0) { predicate = const_1.truthyArrayItemsPredicate; }
var shouldInvoke = predicate(conditions);
// eslint-disable-next-line @typescript-eslint/ban-types
var deps = react_1.useRef();
// we want callback invocation only in case all conditions matches predicate
if (shouldInvoke) {
deps.current = {};
}
// we can't avoid on-mount invocations so slip noop callback for the cases we dont need invocation
// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useEffect(shouldInvoke ? callback : const_1.noop, [deps.current]);
function useConditionalEffect(callback, conditions, deps, predicate) {
if (predicate === void 0) { predicate = __1.truthyAndArrayPredicate; }
// eslint-disable-next-line consistent-return
react_1.useEffect(function () {
if (predicate(conditions)) {
return callback();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}
exports.useConditionalEffect = useConditionalEffect;

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

import { EffectCallback } from 'react';
import { DependencyList, EffectCallback } from 'react';
export declare type IUseConditionalUpdateEffectPredicate<Cond extends ReadonlyArray<any>> = (conditions: Cond) => boolean;

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

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,2 +15,2 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
export declare function useConditionalUpdateEffect<T extends ReadonlyArray<any>>(callback: EffectCallback, conditions: T, predicate?: IUseConditionalUpdateEffectPredicate<T>): void;
export declare function useConditionalUpdateEffect<T extends ReadonlyArray<unknown>>(callback: EffectCallback, conditions: T, deps?: DependencyList, predicate?: IUseConditionalUpdateEffectPredicate<T>): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useConditionalUpdateEffect = void 0;
var react_1 = require("react");
var const_1 = require("../util/const");
var __1 = require("..");

@@ -12,2 +10,4 @@ /**

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -17,17 +17,11 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function useConditionalUpdateEffect(callback, conditions, predicate) {
if (predicate === void 0) { predicate = const_1.truthyArrayItemsPredicate; }
var isFirstMount = __1.useFirstMountState();
var shouldInvoke = !isFirstMount && predicate(conditions);
// eslint-disable-next-line @typescript-eslint/ban-types
var deps = react_1.useRef();
// we want callback invocation only in case all conditions matches predicate
if (shouldInvoke) {
deps.current = {};
}
// we can't avoid on-mount invocations so slip noop callback for the cases we dont need invocation
// eslint-disable-next-line react-hooks/exhaustive-deps
react_1.useEffect(shouldInvoke ? callback : const_1.noop, [deps.current]);
function useConditionalUpdateEffect(callback, conditions, deps, predicate) {
if (predicate === void 0) { predicate = __1.truthyAndArrayPredicate; }
// eslint-disable-next-line consistent-return
__1.useUpdateEffect(function () {
if (predicate(conditions)) {
return callback();
}
}, deps);
}
exports.useConditionalUpdateEffect = useConditionalUpdateEffect;
export declare const noop: () => void;
export declare const isBrowser: boolean;
export declare function truthyArrayItemsPredicate(conditions: ReadonlyArray<any>): boolean;
export declare function truthyAndArrayPredicate(conditions: ReadonlyArray<unknown>): boolean;
export declare function truthyOrArrayPredicate(conditions: ReadonlyArray<unknown>): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.truthyArrayItemsPredicate = exports.isBrowser = exports.noop = void 0;
exports.truthyOrArrayPredicate = exports.truthyAndArrayPredicate = exports.isBrowser = exports.noop = void 0;
var noop = function () { };

@@ -9,6 +9,9 @@ exports.noop = noop;

typeof document !== 'undefined';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function truthyArrayItemsPredicate(conditions) {
function truthyAndArrayPredicate(conditions) {
return conditions.every(function (i) { return Boolean(i); });
}
exports.truthyArrayItemsPredicate = truthyArrayItemsPredicate;
exports.truthyAndArrayPredicate = truthyAndArrayPredicate;
function truthyOrArrayPredicate(conditions) {
return conditions.some(function (i) { return Boolean(i); });
}
exports.truthyOrArrayPredicate = truthyOrArrayPredicate;

@@ -38,1 +38,2 @@ export { useDebouncedCallback } from './useDebouncedCallback/useDebouncedCallback';

export { useEventListener } from './useEventListener/useEventListener';
export { truthyAndArrayPredicate, truthyOrArrayPredicate } from './util/const';

@@ -46,1 +46,2 @@ // Callback

export { useEventListener } from "./useEventListener/useEventListener.js";
export { truthyAndArrayPredicate, truthyOrArrayPredicate } from "./util/const.js";

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

import { EffectCallback } from 'react';
import { DependencyList, EffectCallback } from 'react';
export declare type IUseConditionalEffectPredicate<Cond extends ReadonlyArray<any>> = (conditions: Cond) => boolean;

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

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,2 +15,2 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
export declare function useConditionalEffect<T extends ReadonlyArray<any>>(callback: EffectCallback, conditions: T, predicate?: IUseConditionalEffectPredicate<T>): void;
export declare function useConditionalEffect<T extends ReadonlyArray<unknown>>(callback: EffectCallback, conditions: T, deps?: DependencyList, predicate?: IUseConditionalEffectPredicate<T>): void;

@@ -1,3 +0,3 @@

import { useEffect, useRef } from 'react';
import { noop, truthyArrayItemsPredicate } from "../util/const.js";
import { useEffect } from 'react';
import { truthyAndArrayPredicate } from '..';
/**

@@ -8,2 +8,4 @@ * Like `useEffect` but callback invoked only if conditions match predicate.

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,15 +15,11 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useConditionalEffect(callback, conditions, predicate) {
if (predicate === void 0) { predicate = truthyArrayItemsPredicate; }
var shouldInvoke = predicate(conditions);
// eslint-disable-next-line @typescript-eslint/ban-types
var deps = useRef();
// we want callback invocation only in case all conditions matches predicate
if (shouldInvoke) {
deps.current = {};
}
// we can't avoid on-mount invocations so slip noop callback for the cases we dont need invocation
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(shouldInvoke ? callback : noop, [deps.current]);
export function useConditionalEffect(callback, conditions, deps, predicate) {
if (predicate === void 0) { predicate = truthyAndArrayPredicate; }
// eslint-disable-next-line consistent-return
useEffect(function () {
if (predicate(conditions)) {
return callback();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}

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

import { EffectCallback } from 'react';
import { DependencyList, EffectCallback } from 'react';
export declare type IUseConditionalUpdateEffectPredicate<Cond extends ReadonlyArray<any>> = (conditions: Cond) => boolean;

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

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,2 +15,2 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
export declare function useConditionalUpdateEffect<T extends ReadonlyArray<any>>(callback: EffectCallback, conditions: T, predicate?: IUseConditionalUpdateEffectPredicate<T>): void;
export declare function useConditionalUpdateEffect<T extends ReadonlyArray<unknown>>(callback: EffectCallback, conditions: T, deps?: DependencyList, predicate?: IUseConditionalUpdateEffectPredicate<T>): void;

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

import { useEffect, useRef } from 'react';
import { noop, truthyArrayItemsPredicate } from "../util/const.js";
import { useFirstMountState } from '..';
import { truthyAndArrayPredicate, useUpdateEffect } from '..';
/**

@@ -9,2 +7,4 @@ * Like `useUpdateEffect` but callback invoked only if conditions match predicate.

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -14,16 +14,10 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useConditionalUpdateEffect(callback, conditions, predicate) {
if (predicate === void 0) { predicate = truthyArrayItemsPredicate; }
var isFirstMount = useFirstMountState();
var shouldInvoke = !isFirstMount && predicate(conditions);
// eslint-disable-next-line @typescript-eslint/ban-types
var deps = useRef();
// we want callback invocation only in case all conditions matches predicate
if (shouldInvoke) {
deps.current = {};
}
// we can't avoid on-mount invocations so slip noop callback for the cases we dont need invocation
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(shouldInvoke ? callback : noop, [deps.current]);
export function useConditionalUpdateEffect(callback, conditions, deps, predicate) {
if (predicate === void 0) { predicate = truthyAndArrayPredicate; }
// eslint-disable-next-line consistent-return
useUpdateEffect(function () {
if (predicate(conditions)) {
return callback();
}
}, deps);
}
export declare const noop: () => void;
export declare const isBrowser: boolean;
export declare function truthyArrayItemsPredicate(conditions: ReadonlyArray<any>): boolean;
export declare function truthyAndArrayPredicate(conditions: ReadonlyArray<unknown>): boolean;
export declare function truthyOrArrayPredicate(conditions: ReadonlyArray<unknown>): boolean;

@@ -5,5 +5,7 @@ export var noop = function () { };

typeof document !== 'undefined';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function truthyArrayItemsPredicate(conditions) {
export function truthyAndArrayPredicate(conditions) {
return conditions.every(function (i) { return Boolean(i); });
}
export function truthyOrArrayPredicate(conditions) {
return conditions.some(function (i) { return Boolean(i); });
}

@@ -38,1 +38,2 @@ export { useDebouncedCallback } from './useDebouncedCallback/useDebouncedCallback';

export { useEventListener } from './useEventListener/useEventListener';
export { truthyAndArrayPredicate, truthyOrArrayPredicate } from './util/const';

@@ -46,1 +46,2 @@ // Callback

export { useEventListener } from "./useEventListener/useEventListener.js";
export { truthyAndArrayPredicate, truthyOrArrayPredicate } from "./util/const.js";

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

import { EffectCallback } from 'react';
import { DependencyList, EffectCallback } from 'react';
export declare type IUseConditionalEffectPredicate<Cond extends ReadonlyArray<any>> = (conditions: Cond) => boolean;

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

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,2 +15,2 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
export declare function useConditionalEffect<T extends ReadonlyArray<any>>(callback: EffectCallback, conditions: T, predicate?: IUseConditionalEffectPredicate<T>): void;
export declare function useConditionalEffect<T extends ReadonlyArray<unknown>>(callback: EffectCallback, conditions: T, deps?: DependencyList, predicate?: IUseConditionalEffectPredicate<T>): void;

@@ -1,3 +0,3 @@

import { useEffect, useRef } from 'react';
import { noop, truthyArrayItemsPredicate } from "../util/const.js";
import { useEffect } from 'react';
import { truthyAndArrayPredicate } from '..';
/**

@@ -8,2 +8,4 @@ * Like `useEffect` but callback invoked only if conditions match predicate.

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,14 +15,10 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useConditionalEffect(callback, conditions, predicate = truthyArrayItemsPredicate) {
const shouldInvoke = predicate(conditions);
// eslint-disable-next-line @typescript-eslint/ban-types
const deps = useRef();
// we want callback invocation only in case all conditions matches predicate
if (shouldInvoke) {
deps.current = {};
}
// we can't avoid on-mount invocations so slip noop callback for the cases we dont need invocation
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(shouldInvoke ? callback : noop, [deps.current]);
export function useConditionalEffect(callback, conditions, deps, predicate = truthyAndArrayPredicate) {
// eslint-disable-next-line consistent-return
useEffect(() => {
if (predicate(conditions)) {
return callback();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}

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

import { EffectCallback } from 'react';
import { DependencyList, EffectCallback } from 'react';
export declare type IUseConditionalUpdateEffectPredicate<Cond extends ReadonlyArray<any>> = (conditions: Cond) => boolean;

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

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -13,2 +15,2 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
export declare function useConditionalUpdateEffect<T extends ReadonlyArray<any>>(callback: EffectCallback, conditions: T, predicate?: IUseConditionalUpdateEffectPredicate<T>): void;
export declare function useConditionalUpdateEffect<T extends ReadonlyArray<unknown>>(callback: EffectCallback, conditions: T, deps?: DependencyList, predicate?: IUseConditionalUpdateEffectPredicate<T>): void;

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

import { useEffect, useRef } from 'react';
import { noop, truthyArrayItemsPredicate } from "../util/const.js";
import { useFirstMountState } from '..';
import { truthyAndArrayPredicate, useUpdateEffect } from '..';
/**

@@ -9,2 +7,4 @@ * Like `useUpdateEffect` but callback invoked only if conditions match predicate.

* @param conditions Conditions array
* @param deps Dependencies list like for `useEffect`. If set - effect will be
* triggered when deps changed AND conditions are satisfying predicate.
* @param predicate Predicate that defines whether conditions satisfying certain

@@ -14,15 +14,9 @@ * provision. By default, it is all-truthy provision, meaning that all

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useConditionalUpdateEffect(callback, conditions, predicate = truthyArrayItemsPredicate) {
const isFirstMount = useFirstMountState();
const shouldInvoke = !isFirstMount && predicate(conditions);
// eslint-disable-next-line @typescript-eslint/ban-types
const deps = useRef();
// we want callback invocation only in case all conditions matches predicate
if (shouldInvoke) {
deps.current = {};
}
// we can't avoid on-mount invocations so slip noop callback for the cases we dont need invocation
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(shouldInvoke ? callback : noop, [deps.current]);
export function useConditionalUpdateEffect(callback, conditions, deps, predicate = truthyAndArrayPredicate) {
// eslint-disable-next-line consistent-return
useUpdateEffect(() => {
if (predicate(conditions)) {
return callback();
}
}, deps);
}
export declare const noop: () => void;
export declare const isBrowser: boolean;
export declare function truthyArrayItemsPredicate(conditions: ReadonlyArray<any>): boolean;
export declare function truthyAndArrayPredicate(conditions: ReadonlyArray<unknown>): boolean;
export declare function truthyOrArrayPredicate(conditions: ReadonlyArray<unknown>): boolean;

@@ -5,5 +5,7 @@ export const noop = () => { };

typeof document !== 'undefined';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function truthyArrayItemsPredicate(conditions) {
export function truthyAndArrayPredicate(conditions) {
return conditions.every((i) => Boolean(i));
}
export function truthyOrArrayPredicate(conditions) {
return conditions.some((i) => Boolean(i));
}
{
"name": "@react-hookz/web",
"version": "3.8.0",
"version": "4.0.0",
"description": "React hooks done right, for browser and SSR.",

@@ -5,0 +5,0 @@ "keywords": [

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