$subscribed not triggered when an optional property is set first time #1192
Replies: 2 comments 2 replies
-
@ygyg70 provide additional info: set value to optional prop won't trigger the watch , I don't know how to make it work. @posva , could you pls help on this? It seems lots of question on optional property. pinia/packages/pinia/src/store.ts Line 391 in 2b998ee |
Beta Was this translation helpful? Give feedback.
-
I switched from Vuex to Pinia, had to spend time to troubleshoot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
Steps to reproduce the bug
export interface StateInterface {
prop?:string
}
export const useStore = defineStore( 'store', {
state: ():StateInterface => ( { } )
})
Note - if $patch is used to set the value, subscribe will trigger
Expected behavior
$subscribe will trigger when a value is set for the first time
Actual behavior
For $subscribe to trigger, property has to be initiated as null
Additional information
No response
Beta Was this translation helpful? Give feedback.
All reactions