Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 701 Bytes

File metadata and controls

41 lines (33 loc) · 701 Bytes

tinystore

Installation

npm install @tinyhref/tinystore
or
yarn add @tinyhref/tinystore

Use It

import React from 'react';
import { useStore } from '@tinyhref/tinystore';

function Counter() {
  const storeMethods = useStore({
    storeKey: '', // optional
    initialState: {
      count: 0
    },
    handlers: ({ setState }) => {
      return {
        inc: () => setState((state) => ({ count: state.count + 1 }))
      }
    }
  });

  const { useStoreSelector, handlers } = storeMethods;

  const count = useStoreSelector(state => state.count);

  return (
    <div>
      <span>{count}</span>
      <button onClick={handlers.inc}>one up</button>
    </div>
  )
}