Skip to content

[@xstate/store] Add reset extension#5474

Merged
davidkpiano merged 10 commits intomainfrom
davidkpiano/xstate-store-reset
Mar 5, 2026
Merged

[@xstate/store] Add reset extension#5474
davidkpiano merged 10 commits intomainfrom
davidkpiano/xstate-store-reset

Conversation

@davidkpiano
Copy link
Member

Add reset store extension for resetting store context to its initial state via .with(reset()).

import { createStore } from '@xstate/store';
import { reset } from '@xstate/store/reset';

const store = createStore({
  context: { count: 0, user: null },
  on: {
    inc: (ctx) => ({ ...ctx, count: ctx.count + 1 }),
    login: (ctx, e: { user: string }) => ({ ...ctx, user: e.user })
  }
}).with(reset());

store.trigger.inc();
store.trigger.reset(); // resets to { count: 0, user: null }

Supports custom reset logic via to for partial resets:

.with(reset({
  to: (initial, current) => ({ ...initial, user: current.user })
}))

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 179a28e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@xstate/store Minor
@xstate/store-angular Patch
@xstate/store-preact Patch
@xstate/store-react Patch
@xstate/store-solid Patch
@xstate/store-svelte Patch
@xstate/store-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Base automatically changed from davidkpiano/xstate-store-persist to main March 5, 2026 15:11
@davidkpiano davidkpiano merged commit e299d40 into main Mar 5, 2026
1 check passed
@davidkpiano davidkpiano deleted the davidkpiano/xstate-store-reset branch March 5, 2026 18:32
@github-actions github-actions bot mentioned this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant