Pinia-React stores can be used inside and outside of React components. While useStore() is a hook designed for components, you can use the getStore() function for all other scenarios.
getStore functionWhen you define a store, defineStore() returns an object containing both useStore (the hook) and getStore (a plain function).
The recommended pattern is to export both from your store definition file.
Now, you can import getAuthStore in any JavaScript module, like a service file, an API client, or another store's action.
Here is an example of calling a store's action from a utility function:
This pattern ensures that you are always accessing the same, single instance of the store throughout your application, whether you are in a component or not.