Issue
I'm trying to have a getter that return all state properties of my pinia store.
export const useFilterStore = defineStore('filterStore', {
    state : () : FilterState => ({
        variables:[] as string[],
        categories:[] as string[]
    }),
    getters: {
        getFilters: (state) => state
    },
    actions : {}
  });
Doing it this way , getFilters references itself generating circular reference on different situation, as illustrated in this component
import { useFilterStore } from './store/filter-store.js'
export default {
  name: 'App',
  setup() {
    const filter = useFilterStore()
    JSON.stringify(filter.getFilters)  --> cyclic object value
  }
}
Is there a way to set up a getter for the whole state object directly?
Solution
getFilters doesn't serve a good purpose. state is the whole store, not just state data, accessing state.getFilters results in a recursion.
It should be:
 JSON.stringify(filter.$state)
Answered By - Estus Flask Answer Checked By - Terry (PHPFixing Volunteer)
 
 Posts
Posts
 
 
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.