# change-notifier

> Dead-simple state notifier for React. Under 1kb. Inspired by Flutter.

Latest version **1.0.1** (published 2020-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install change-notifier
pnpm add change-notifier
yarn add change-notifier
bun add change-notifier
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-10-06 |
| First published | 2020-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 39.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Michael Bullington |
| Maintainers | mbullington |

## Links

- npm: https://www.npmjs.com/package/change-notifier
- npm.io page: https://npm.io/package/change-notifier

## Recent versions

- 1.0.1 (latest) — 2020-10-06
- 1.0.0 — 2020-10-03

## README

# change-notifier

[![Actions Status](https://github.com/mbullington/change-notifier/workflows/CI/badge.svg)](https://github.com/mbullington/change-notifier/actions)

[![npm version](https://badge.fury.io/js/change-notifier.svg)](https://badge.fury.io/js/change-notifier)

Dead-simple state notifier for React. Under 1kb. Inspired by (meaning ported from!) Flutter.

```sh
yarn add change-notifier
```

## Inspiration

Made this to scratch a personal itch where I wanted to use `EventEmitter` as a lightweight state tool for React,
to which `tiny-emitter` is an awesome package for React Native! However, hooks weren't built in.

While considering building a `useTinyEmitter` hook, I remembered that Flutter had a similar pattern that I really liked.

## Example

```ts
import React from 'react';
import {
  ChangeNotifier,
  useChangeNotifier,
  ValueNotifier,
  useValueNotifier,
} from 'change-notifier';

class Timer extends ChangeNotifier {
  constructor() {
    setInterval(() => {
      this.notifyListeners();
    }, 1000);
  }
}

class TimerAlt extends ValueNotifier<number> {
  constructor() {
    super(Date.now());

    setInterval(() => {
      this.value = Date.now();
    }, 1000);
  }
}

const TIMER = new Timer();
const TIMER_ALT = new TimerAlt();

function App() {
  useChangeNotifier(TIMER);

  return (
    <>
      <div>The timestamp is:</div>
      <div>{Date.now()}</div>
    </>
  );
}

function AppAlt() {
  const now = useValueNotifier(TIMER_ALT);

  return (
    <>
      <div>The timestamp is:</div>
      <div>{now}</div>
    </>
  );
}
```

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