You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the component you can increment the count add values to the array or change data's value.
Since $reset method is not available in a "Setup" store I used a plugin:
import cloneDeep from 'lodash.clonedeep'
export default function storeReset({ store }) {
const initialState = cloneDeep(store.$state)
store.$reset = () => store.$patch(cloneDeep(initialState))
}
When I use the $reset the count goes back to 0 and the array is emptied but not the object.
When debugging the value of initialState is correct with data being an empty object. But the $patch doesn't actually change the value in the store.
Expected behavior
I expected the state of the object data to be an empty object on reset.
Actual behavior
$reset doesn't reset an objects value to the initial state
Additional information
No response
The text was updated successfully, but these errors were encountered:
Then in your custom $reset function after you apply $patch of initialState which has data as {} it properly patches the store.data state with no updates.
importcloneDeepfrom'lodash.clonedeep'exportdefaultfunctionstoreReset({ store }){constinitialState=cloneDeep(store.$state)store.$reset=()=>{store.$patch($state=>{Object.assign($state,initialState)})}}
Reproduction
https://stackblitz.com/edit/vue3-reset-pinia-store-qt5yn7
Steps to reproduce the bug
From the stackblitz above:
I created a "Setup" store with 3 varibales in my state:
On the component you can increment the count add values to the array or change data's value.
Since $reset method is not available in a "Setup" store I used a plugin:
When I use the $reset the count goes back to 0 and the array is emptied but not the object.
When debugging the value of initialState is correct with data being an empty object. But the $patch doesn't actually change the value in the store.
Expected behavior
I expected the state of the object data to be an empty object on reset.
Actual behavior
$reset doesn't reset an objects value to the initial state
Additional information
No response
The text was updated successfully, but these errors were encountered: