Skip to content
Discussion options

You must be logged in to vote

Yes, good idea. Here's an example:

// Example of a counter store with localStorage persistence
const savedSnapshot = localStorage.getItem('store');
const initialSnapshot = savedSnapshot ? JSON.parse(savedSnapshot) : {
  context: {
    count: 0,
    lastUpdated: Date.now(),
    // ... any other state properties
  }
};

const counterStore = createStore({
  context: initialSnapshot.context,
  on: {
    increment: (context, event: { amount: number }) => ({
      ...context,
      count: context.count + event.amount,
      lastUpdated: Date.now()
    }),
    decrement: (context, event: { amount: number }) => ({
      ...context,
      count: context.count - event.amount,
      lastUpdated: Date.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jericopulvera
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