0.0.0-dev-20240511210804 • Published 9 months ago

@passionware/simple-store v0.0.0-dev-20240511210804

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

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