question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't reset store state / patch with pinia@2.0.0-rc.0

See original GitHub issue

First of all thank you for your amazing work, I’m really excited to try all the new features coming into Pinia.

Reproduction

I tried the new version of pinia and it seems the store.$reset() is no longer working or the api changed.

I created a repro with the issue: https://github.com/slauzinho/pinia-example-reset

Steps to reproduce the behavior

  1. Call store.$reset
  2. State remains the same

Expected behavior

State should be the same as the initial

Actual behavior

State doesn’t change

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Blackfadedcommented, Sep 3, 2021

Solved it by replacing the state definition from

  state: () => initialConfiguratorState,

to

  state: () => {
    return { ...initialConfiguratorState };
  },
2reactions
quantuminformationcommented, Apr 1, 2022

@Blackfaded I have this:


beforeEach(() => {
  setActivePinia(createPinia())
  store = useVideoPlayerStore()
  store.$reset()
})
afterEach(() => {
  store.$reset()
})

and

export const useVideoPlayerStore = defineStore("videoPlayerStore", {
  state: () => ({ ...initialVideoPlayerState }),

And still get state preserved across tests

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't reset store state / patch with pinia@2.0.0-rc.0 · Issue #593
Reproduction. I tried the new version of pinia and it seems the store.$reset() is no longer working or the api changed.
Read more >
Pinia: How to reset stores created with function/setup syntax
Learn how to reset stores made with function syntax by creating a Pinia plugin. ... Pinia is a state management solution for Vue...
Read more >
How to reset the state of a Redux store? - Stack Overflow
One way to do that would be to write a root reducer in your application. The root reducer would normally delegate handling the...
Read more >
Can't reset store state / patch with pinia@2.0.0-rc.0
I tried the new version of pinia and it seems the store.$reset() is no longer working or the api changed. I created a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found