@utilityjs/use-on-change
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

useOnChange

A React hook that invokes a callback anytime a value changes.

license npm latest package npm downloads types

npm i @utilityjs/use-on-change | yarn add @utilityjs/use-on-change

Usage

import useOnChange from "@utilityjs/use-on-change";
import * as React from "react";

const MyComponent = (props) => {
  useOnChange(props.isOpen, (currentOpenState) => {
    console.log(`The current open state is: ${currentOpenState}`);
  })

  return ...;
};

API

useOnChange(value, onChange)

declare const useOnChange: <T>(value: T, onChange: (current: T) => void) => void;

value

The value to listen on.

onChange

The callback that is called when value changes.

Package Sidebar

Install

npm i @utilityjs/use-on-change

Weekly Downloads

4

Version

1.0.3

License

MIT

Unpacked Size

5.05 kB

Total Files

8

Last publish

Collaborators

  • mimshins