Skip to content

Commit 395e450

Browse files
committed
fix: create store type differenciation
1 parent 750229a commit 395e450

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.changeset/friendly-emus-beam.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@dojoengine/sdk": patch
3+
"template-vite-ts": patch
4+
"@dojoengine/core": patch
5+
"@dojoengine/create-burner": patch
6+
"@dojoengine/create-dojo": patch
7+
"@dojoengine/predeployed-connector": patch
8+
"@dojoengine/react": patch
9+
"@dojoengine/state": patch
10+
"@dojoengine/torii-client": patch
11+
"@dojoengine/torii-wasm": patch
12+
"@dojoengine/utils": patch
13+
"@dojoengine/utils-wasm": patch
14+
---
15+
16+
fix: createStore now fit to either vanilla or react store

packages/sdk/src/react/hooks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { useContext } from "react";
22
import { BigNumberish } from "starknet";
33
import { SchemaType } from "../types";
44
import { DojoContext, DojoContextType } from "./provider";
5-
import { create } from "zustand";
5+
import { create, StoreApi, UseBoundStore } from "zustand";
66
import { createDojoStoreFactory } from "../state/zustand";
7+
import { GameState } from "../state";
78

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

1822
/**

packages/sdk/src/state/zustand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type StateCreator, type StoreApi } from "zustand";
1+
import { UseBoundStore, type StateCreator, type StoreApi } from "zustand";
22
import { immer } from "zustand/middleware/immer";
33
import { Draft, WritableDraft, applyPatches, produceWithPatches } from "immer";
44

0 commit comments

Comments
 (0)