In the Vuex documentation, there is a quote that discusses when it's appropriate to use the state management library:
When Should I Use It?
Vuex is helpful for managing shared state in applications, but it does come with added complexity and boilerplate code. It's a trade-off between immediate productivity and long-term maintainability.
If you are new to building large-scale single-page applications (SPAs) and dive straight into using Vuex, it may seem overwhelming and verbose at first. In simpler apps, a basic store pattern might suffice. However, as your app grows in size and complexity, situations will arise where handling state outside of Vue components becomes necessary, making Vuex a logical next step. To paraphrase Dan Abramov, the creator of Redux:
"Flux libraries are like glasses: you’ll know when you need them."
As components grow larger with multiple states and mutations, maintaining and extending their code can become difficult. Decoupling state storage and modification from the components themselves becomes crucial in such scenarios.
When several components trigger the same actions or mutations, extracting these to a common source prevents duplication of logic. Implementing this approach brings your structure closer to a Vuex-like setup.
In cases where an application communicates with a backend API involving asynchronous requests and error handling, separating these concerns from the component file improves readability and organization.
By isolating mutations within a separate Vuex module, testing becomes easier without the need to instantiate Vue components. This allows components to focus on display logic and event handling.
The main goal is to provide your application with a clear and organized structure, which ultimately makes maintenance more manageable in a larger application.
While Vuex offers beneficial features like state tracking and rollback through Vue.js devtools, it is not always essential and should be used judiciously to avoid unnecessary verbosity.
Update
Reflecting on my experience, I have reduced the amount of state stored in Vuex. Instead, I now store transient state specific to a "page" or route directly in the parent component, passing it down through properties. This cleanup process helps prevent stale entries in the store and reduces memory usage during long sessions in the app.
For further insights, check out these interesting articles:
https://i.sstatic.net/lF5qk.jpg