Is it possible to access useStore from another useXxx composable?

Hi,

I’m trying to get access to the Vuex Store from another composable and it seems that it is not possible to do it outside the setup() function from a component.

If I try something like:

import { useStore } from 'vuex'
export default function useAuth () {
    const $store = useStore()
    ...
    $store.dispatch(...)
}

I get a console error saying $store is undefined.

Any thoughts?

TIA

You should be able to call useStore from within your composable, so long as the composable itself is called from within setup. The usual rules apply that it must be called during the synchronous execution of setup, not within an asynchronous callback.

To narrow down the problem, I suggest calling useStore within your setup function, immediately before you call useAuth, to confirm that it can access the store from there.

That should do it. Thanks a lot!