@passionware/simple-store

0.0.0-dev-20240511210804 • Public • Published

Simple store

Simple Store is a lightweight state hook that which functions similarly to the React's useState() hook but enables data sharing between instances created using the same factory.

Simple Store is particularly useful for test and Storybook code. It allows you to expose mock hook implementations within a factory, enabling data sharing without the need for specialized contexts.

Usage

const createMockItemsDomain = (initialData) => {

  const itemsStore = createSimpleStore(initialData);

  return {
    useAddItem: () => {
      const [value, setValue] = itemsStore.useValue();
      return (item) => {
        itemsStore.setValue([...value, item]);
      };
    },
    useItems: () => {
      const [value, setValue] = itemsStore.useValue();
      return value;
    },
  };
};

Readme

Keywords

none

Package Sidebar

Install

npm i @passionware/simple-store

Weekly Downloads

150

Version

0.0.0-dev-20240511210804

License

none

Unpacked Size

4.74 kB

Total Files

7

Last publish

Collaborators

  • borovsky