use-shallow-effect
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

use-shallow-effect

useEffect with shallow comparison. Additionaly, a shallow comparison function.

Description

Optimising useEffect hook with a shallow comparison of it's dependency list, providing better performance than deep-comparison or stock useEffect.

Features

  • useShallowEffect.
  • shallow comparison function.
  • Super Light and Fast.
  • Thoroughly tested.

Installation

npm install use-shallow-effect

Usage

using useShallowEffect -

import { useShallowEffect } from 'useShallowCompare';

useShallowEffect(() => {
    //side-effects generally used, similar to useEffect
}, dependency_list);

using the shallow comparison function -

import shallowCompare from 'useShallowCompare';

console.log(shallowCompare(a,b));//returns boolean

Shallow Comparison in words -

  • Object.is comparison between primitive types.
  • For other objects, iterate through their keys and comparing their values with ===

Currently supporting - primitive types, arrays, objects, map, set, date.

Package Sidebar

Install

npm i use-shallow-effect

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

6.99 kB

Total Files

9

Last publish

Collaborators

  • achmurali