store-wizard
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

Store Wizard 🧙‍♂️

Install

  npm i store-wizard

How to use?

Create a file createStoreHook.ts and:

import { initStore } from "store-wizard";

export type Store = {
  count: number;
  name: string;
};

const { createStoreHook } = initStore<Store>({ count: 0 });

export default createStoreHook;

In a React component TestComponent.tsx you can do the following:

import createStoreHook, { Store } from "./createStoreHook";

const useStore = createStoreHook();

const selectCount = (state: Store) => state.count;

type CountSelector = typeof selectCount;

const TestComponent = () => {
  const [count, setStore] = useStore<CountSelector>(selectCount);

  return (
    <div>
      <div>{count}</div>
      <div>
        <button
          onClick={() =>
            setStore((prevState) => ({ ...prevState, count: count + 1 }))
          }
        >
          [+] Increment
        </button>
      </div>
    </div>
  );
};

export default TestComponent;

Still under construction! ⚒️

Readme

Keywords

none

Package Sidebar

Install

npm i store-wizard

Weekly Downloads

0

Version

0.0.13

License

ISC

Unpacked Size

53 kB

Total Files

7

Last publish

Collaborators

  • aelsherif