Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

murilo's avatar
Level 10

Can I have a Getter and State with same name in Pinia ?

hello , I used to work with Vuex , now I am starting to work with Pinia . I have a question . Can I use the same name for State and Getter in Pinia ? I used to do this in VUEX for some state that I want to pass some extra value to it . for example , I have a State that is called products , and I have a initial value that I store when my page is created .

In VUEX -

// initial values is in case that you want to reset thouse values for initial values
state -
products: {value: [], initial_values:[] }

Getter - 
products: state => {    
    return products.value   
}


// list products -
{{ products }} 


  ...mapGetters('products', {
      products: 'products'
    })

In PInia -

state -
products: {value: [], initial_values:[] }

Getter - 
productsValue: state => {    
    return products.value   
}

// list products -
{{ storeProduct.productsValue }} 


import {useProductStore} from "stores/admin/products"
const storeProduct = useProductStore()


if in pinia I have the same state with the same name like this , it will not be possible , I must change the name -

state -
products: {value: [], initial_values:[] }

Getter - 
products: state => {    
    return products.value   
}

// list products -
{{ storeProduct.products }} 


import {useProductStore} from "stores/admin/products"
const storeProduct = useProductStore()


does have any way to do some thing like this in Pinia ?

to shows that I am reffering to a Getter and not to a State something like this ?

// list products -
{{ storeProduct.getters.products }} 

0 likes
1 reply
lbecket's avatar
lbecket
Best Answer
Level 39

No, you cannot use the same name for state and getter in Pinia as they both belong to the same object and naming them the same will cause a naming collision. To access the getter in Pinia, you should use the dot notation on the store instance followed by the getter name.

In your example, you can access the productsValue getter like this:

{{ storeProduct.productsValue }}
1 like

Please or to participate in this conversation.