Skip to content

New api for Store based on Hooks #88

Description

@UpperCod

Describe the solution you'd like

What if we use hooks inside a state manager? 🤔... Imagine reusing custom Hooks even in the Store, example:

import { createStore } from "@atomico/hooks/store";
import { usePromise } from "@atomico/hooks/use-promise";

const store = createStore(
  {
    products: {},
  },
  {
    getProducts(store) {
      const [result, status] = usePromise(() => myApi(`/products`));
      
      return {
        products: {
          result,
          status,
        },
      };
    },
  }
);

store.actions.getProducts();

const { result, status } = store.state.products;

Additional context

The goal of this API is to reuse customHooks to compose states at the Store level.

✍️ All positive or negative opinions about this proposal are welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions