Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create store type differenciation #390

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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