An open API service indexing awesome lists of open source software.

https://github.com/ythecombinator/deeply-checked-effect

React hook for providing an alternative for useEffect that does a deep comparison of passed objects
https://github.com/ythecombinator/deeply-checked-effect

hooks hooks-api-react react useeffect

Last synced: about 2 months ago
JSON representation

React hook for providing an alternative for useEffect that does a deep comparison of passed objects

Awesome Lists containing this project

README

          

# `@rehooks/deeply-checked-effect`

> React hook for handling deep object comparison in React's `useEffect` hook.

> **Note:** This is using the new [React Hooks API Proposal](https://reactjs.org/docs/hooks-intro.html)
> which is subject to change until React 16.7 final.
>
> You'll need to install `react`, `react-dom`, etc at `^16.7.0-alpha.0`

## Install

```sh
yarn add @rehooks/deeply-checked-effect
```

## Usage

### Sample

```jsx
import useEffect from "@rehooks/deeply-checked-effect";

function UseEffect({ state }) {
useEffect(
() => {
console.log("useEffect", state);
},
[state]
);

return

;
}
```

### API

The `useEffect(create, inputs)` hook takes two parameters and has no return. The mentioned parameters are:

#### `create`

A function that contains imperative, possibly effectful code and is directly invoked inside a regular React's `useEffect` hook.

#### `inputs`

The array of values that the effect depends on and that will be deeply compared for changes.