# use-changed-props

> React Hook to output props that have changed

Latest version **0.1.0** (published 2022-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-changed-props
pnpm add use-changed-props
yarn add use-changed-props
bun add use-changed-props
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-08-04 |
| First published | 2020-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 84.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Moz Morris |
| Maintainers | mozmorris |
| Keywords | react, react hooks, props |

## Links

- npm: https://www.npmjs.com/package/use-changed-props
- Repository: https://github.com/mozmorris/use-changed-props
- Issues: https://github.com/mozmorris/use-changed-props/issues
- npm.io page: https://npm.io/package/use-changed-props

## Dependencies (2)

- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.15
- [deep-object-diff](https://npm.io/package/deep-object-diff.md) ^1.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-08-04
- 0.0.2 — 2020-04-24
- 0.0.1 — 2020-04-23

## README

# use-changed-props

A React hook to log which props have changed. The hook will also include the changes for each prop, which is useful for tracking down unnecessary work when nothing really changed eg. a reference was updated.

https://www.npmjs.com/package/use-changed-props

## Demo

https://codepen.io/mozmorris/pen/BaopXRX?editors=1111

## Installation

```
npm install use-changed-props
```

or

```
yarn add use-changed-props
```

## Usage

### Log changed props to console

```jsx
import useChangedProps from "use-changed-props"

const App = props => {

  // log props changes
  useChangedProps(props)

  return </div>
}
```

### Disable logging

```jsx
import useChangedProps from "use-changed-props"

const App = props => {

  // disable logging
  const options = { log: false }

  // store changed props
  const changedProps = useChangedProps(props, options)

  return </div>
}
```


## Options

| Option                | Description                                                               |  Default     |
| --------------------- | --------------------------------------------------------------------------|------------- |
| `log`                 | Should automatically log prop changes to the console                      | `true`       |

## License

MIT

## Motivation

"How to check what props have changed?"

"Determine which props caused a re-render"

I've found myself Googling these questions on more than one occasion. Ideally I can now just drop this hook in to my component and get feedback about which props have changed and also the differences.

---
_Source: https://npm.io/package/use-changed-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
