Skip to content

Call actions within actions, in a typesafe way? #750

Answered by frontshift
isaachinman asked this question in Q&A
Discussion options

You must be logged in to vote

I only started out yesterday with Zustand, so forgive me if this is not good practice. I would like to use Immer and also plan to always declare my actions outside of the store so that all my actions actions

  • don't have to be accessed via the store as in const increasePopulation = useStore(state => state.increasePopulation)
  • Don't have to be added to the store interface
  • Can easily be called from anywhere within my app without using useStore.getState().myAction (I don't have to reference my store anywhere except in the actions file)

I created a base store which only has a set() function, which basically just acts as a proxy for Immer's produce() method.

// TODO: Using NamedSet her as the 3…

Replies: 5 comments 20 replies

Comment options

You must be logged in to vote
1 reply
@devanshj
Comment options

Comment options

You must be logged in to vote
16 replies
@ddanielgal
Comment options

@dai-shi
Comment options

@KamalakannanKrishnaraj15
Comment options

@dai-shi
Comment options

@KamalakannanKrishnaraj15
Comment options

Answer selected by isaachinman
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dai-shi
Comment options

Comment options

You must be logged in to vote
2 replies
@dbritto-dev
Comment options

@dai-shi
Comment options

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