@intrnl/substate-preact
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

substate-preact

import { h } from 'preact';
import { Store } from '@intrnl/substate';
import { useStoreState } from '@intrnl/substate-preact';


let countStore = new Store({
  initialState: {
    count: 0,
  },
});

function increment () {
  countStore.update((store) => ({ count: store.count++ }));
}

function decrement () {
  countStore.update((store) => ({ count: store.count++ }));
}


function App () {
  // Omitting the second parameter returns the whole store value
  let count = useStoreState(countStore, (store) => store.count);

  return (
    <div>
      <span>{count}</span>
      <button onClick={increment}>+</button>
      <button onClick={decrement}>-</button>
    </div>
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i @intrnl/substate-preact

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

2.8 kB

Total Files

5

Last publish

Collaborators

  • intrnl