Skip to content

useShallowCompareEffect

Category
Export Size
404 B
Last Changed
5 days ago

useEffect whose dependency list is compared by one-level (shallow) equality instead of reference identity.

Demo

Usage

tsx
import { 
useShallowCompareEffect
} from '@reause/shared'
const
options
= {
step
: 2 } // rebuilt on every render — shallow-equal to the last one
useShallowCompareEffect
(() => {
inc(
options
.
step
)
}, [
options
]) // runs on mount and whenever `step` changes, not on every re-render

Type Declarations

ts
export function shallowEqual(a: unknown, b: unknown): boolean

export function useShallowCompareEffect(effect: EffectCallback, deps: DependencyList): void

Source

Source · Demo · react-use

Contributors

hairyf

Changelog

v0.1.6 on
214d8 - fix(shared): use the pin's bare NODE_ENV gate for useShallowCompareEffect warnings (#922)
c2c20 - feat(shared): add useShallowCompareEffect (#922)

Released under the MIT License. v0.1.8