npm i @react-hook/change
A React hook that invokes a callback anytime a value changes
import useChange from '@react-hook/change'
const useChangeLog = (value) => {
// Logs the value each time it changes
useChange(value, console.log)
}
const useChange = <T extends any>(
value: T,
onChange: (current: T, prev: T) => any
): void
Argument | Type | Required? | Description |
---|---|---|---|
value | T |
Yes | The value to watch for changes to |
onChange | (current: T, prev: T) => any |
Yes | This callback is invoked any time the value changes |
MIT