@klintm/phase-react

1.0.1 • Public • Published

phase
phase-react

React plugin for the phase micro-store/change emitter


phase-react is the react plugin for phase.

Features

Exports a hook that allows subscribing to a phase store and path.

Installation

npm

npm i @klintm/phase-react

Usage

import Phase from "@klintm/phase";
import { useStore } from "@klintm/phase-react";

const counter = Phase(
  {
    name: "",
    count: 0
  },
  state => ({
    changeName: n => state.set("name", n),
    increment: () => state.set("count", state("count") + 1),
    decrement: () => state.set("count", state("count") - 1)
  })
);

const Counter = () => {
  const state = useStore(counter);
  const { decrement, increment } = state.actions;

  return (
    <div>
      <div>Count: {state("count")}</div>
      <button onClick={decrement}>-</button>
      <button onClick={increment}>+</button>
    </div>
  );
};

Readme

Keywords

none

Package Sidebar

Install

npm i @klintm/phase-react

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.95 kB

Total Files

8

Last publish

Collaborators

  • klintmane