Skip to content

Commit

Permalink
fix: create store type differenciation
Browse files Browse the repository at this point in the history
  • Loading branch information
MartianGreed committed Feb 6, 2025
1 parent 750229a commit e6406f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/sdk/src/react/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useContext } from "react";
import { BigNumberish } from "starknet";
import { SchemaType } from "../types";
import { DojoContext, DojoContextType } from "./provider";
import { create } from "zustand";
import { create, StoreApi, UseBoundStore } from "zustand";
import { createDojoStoreFactory } from "../state/zustand";
import { GameState } from "../state";

/**
* Factory function to create a React Zustand store based on a given SchemaType.
Expand All @@ -12,7 +13,10 @@ import { createDojoStoreFactory } from "../state/zustand";
* @returns A Zustand hook tailored to the provided schema.
*/
export function createDojoStore<T extends SchemaType>() {
return createDojoStoreFactory<T>(create);
// hacktually until I find a proper type input to createDojoStoreFactory
return createDojoStoreFactory<T>(create) as unknown as UseBoundStore<
StoreApi<GameState<T>>
>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/state/zustand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type StateCreator, type StoreApi } from "zustand";
import { UseBoundStore, type StateCreator, type StoreApi } from "zustand";
import { immer } from "zustand/middleware/immer";
import { Draft, WritableDraft, applyPatches, produceWithPatches } from "immer";

Expand Down

0 comments on commit e6406f2

Please sign in to comment.