Skip to content

klintmane/phase-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>
  );
};

About

React plugin for the phase micro-store/change emitter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published