Skip to content

Commit

Permalink
Merge pull request #390 from dojoengine/fix/create-store
Browse files Browse the repository at this point in the history
fix: create store type differenciation
  • Loading branch information
MartianGreed authored Feb 6, 2025
2 parents 81b8de8 + 395e450 commit 1a3eeef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .changeset/friendly-emus-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@dojoengine/sdk": patch
"template-vite-ts": patch
"@dojoengine/core": patch
"@dojoengine/create-burner": patch
"@dojoengine/create-dojo": patch
"@dojoengine/predeployed-connector": patch
"@dojoengine/react": patch
"@dojoengine/state": patch
"@dojoengine/torii-client": patch
"@dojoengine/torii-wasm": patch
"@dojoengine/utils": patch
"@dojoengine/utils-wasm": patch
---

fix: createStore now fit to either vanilla or react store
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 1a3eeef

Please sign in to comment.