# @hocs/with-callback-on-change

> Invokes a callback on prop change as a HOC for React and React Native

Latest version **0.3.1** (published 2019-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hocs/with-callback-on-change
pnpm add @hocs/with-callback-on-change
yarn add @hocs/with-callback-on-change
bun add @hocs/with-callback-on-change
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2019-09-02 |
| First published | 2017-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2039 |
| Author | Kir Belevich |
| Maintainers | hocs |
| Keywords | react, react-native, hoc, recompose, callback |

## Links

- npm: https://www.npmjs.com/package/@hocs/with-callback-on-change
- Repository: https://github.com/deepsweet/hocs
- Homepage: https://github.com/deepsweet/hocs#readme
- Issues: https://github.com/deepsweet/hocs/issues
- npm.io page: https://npm.io/package/@hocs/with-callback-on-change

## Dependencies (1)

- [react-display-name](https://npm.io/package/react-display-name.md) ^0.2.4

## 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.3.1 (latest) — 2019-09-02
- 0.3.0 — 2018-07-15
- 0.2.0 — 2017-10-09
- 0.1.0 — 2017-08-18

## README

# :bell: with-callback-on-change

[![npm](https://img.shields.io/npm/v/@hocs/with-callback-on-change.svg?style=flat-square)](https://www.npmjs.com/package/@hocs/with-callback-on-change) [![ci](https://img.shields.io/travis/deepsweet/hocs/master.svg?style=flat-square)](https://travis-ci.org/deepsweet/hocs) [![coverage](https://img.shields.io/codecov/c/github/deepsweet/hocs/master.svg?style=flat-square)](https://codecov.io/github/deepsweet/hocs) [![deps](https://david-dm.org/deepsweet/hocs.svg?path=packages/with-callback-on-change&style=flat-square)](https://david-dm.org/deepsweet/hocs?path=packages/with-callback-on-change)

Part of a [collection](https://github.com/deepsweet/hocs) of Higher-Order Components for React, especially useful with [Recompose](https://github.com/acdlite/recompose).

Invokes a callback on prop change, useful to decouple side effects like `onChange` handler in a declarative way.

## Install

```
yarn add @hocs/with-callback-on-change
```

## Usage

```js
withCallbackOnChange(
  propName: string,
  callback: (props: Object) => void
): HigherOrderComponent
```

```js
import React from 'react';
import { compose, withState, withHandlers } from 'recompose';
import withCallbackOnChange from '@hocs/with-callback-on-change';

const Demo = ({ count, onButtonClick }) => (
  <div>
    <h1>{count}</h1>
    <button onClick={onButtonClick}>increment</button>
  </div>
);

export default compose(
  withState('count', 'setCount', 0),
  withHandlers({
    onButtonClick: ({ setCount, count }) => () => setCount(count + 1)
  }),
  withCallbackOnChange('count', ({ count }) => console.log(count))
)(Demo);
```

:tv: [Check out live demo](https://codesandbox.io/s/o8m03w7j6).

---
_Source: https://npm.io/package/@hocs/with-callback-on-change · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
