Skip to content

how to infer store type? #2928

Answered by dai-shi
vorant94 asked this question in Q&A
Dec 31, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

There would be several ways, but I'd do this:

const useMyStore = create(combine({
  count: 0,
}, (set) => ({
  inc: (by = 1) => set((state) => ({ count: state.count + by }));
}));

type MyState = ReturnType<(typeof useMyStore)['getState']>;

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@vorant94
Comment options

@dai-shi
Comment options

@vorant94
Comment options

Answer selected by vorant94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants