npm.io
0.1.15 • Published 3 years ago

value-notifier-ts

Licence
MIT
Version
0.1.15
Deps
0
Size
17 kB
Vulns
0
Weekly
0
Stars
1

value-notifier-ts

Inspired by ValueNotifer from Flutter, valueNotifer is a simple way of listening to changes and updating a value.

Example

import { valueNotifer } from "value-notifier-ts";
import { useValueListenable } from "value-notifier-ts/react";

const counter = valueNotifer(0);

export function CounterText() {
  const count = useValueListenable(counter);
  return <div>Current count: {count}</div>;
}

export function CounterButton() {
  const increment = () => counter.update((count) => count + 1);

  return <button onClick={increment}>Increment</button>;
}