Skip to content

How to define store functions outside zustand store with Typescript? #2472

Closed Answered by itsramiel
itsramiel asked this question in Q&A
Discussion options

You must be logged in to vote

I guess I found out:

function makeIncrement(set: StoreApi<TCounterStore>["setState"]): TCounterStore['increment']{
  return function(){
    set((prev) => ({ counter: prev.counter + 1 }))
  }
}

function makeDecrement(set: StoreApi<TCounterStore>["setState"]): TCounterStore['decrement']{
  return function(){
    set((prev) => ({ counter: prev.counter - 1 }))
  }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by itsramiel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant