Working with read state and update state
While Zustand is a library that can be used in various ways, it has a pattern to read state and update state. Let's learn how to use Zustand with a small example.
Here's our small store
with the count1
and count2
properties:
type StoreState = { count1: number; count2: number; }; const useStore = create<StoreState>(() => ({ count1: 0, count2: 0, }));
This creates a new store
with two properties called count1
and count2
. Notice that StoreState
is the type
definition in TypeScript.
Next, we must define...