Hi, everyone. My name is Eduardo. I live in Paris. I'm a frontend developer and also a member of the Vue.js core team. I'm the author of its router and a small library called Pina, which is an alternative to Vue.js, a store library, as well, that I'm going to talk about today.
What I want to talk to you about is not only Pina but what is beyond state management, what matters in state management more than the state itself. But first, before even diving into Pina or anything else, what is state management? It's just having a global object with a few functions like that, global state. You have a function logging that allows you to change a state. Is this state management? And people will tell you that it is. And to be honest, it pretty much is, especially if you just add a reactive function call around that object. Well, you have a completely valid state, global state solution working for your view three or view two application.
And this is still state management and some people will tell you but state management is something you have and you create when you have bigger apps or medium to big apps or when you know your application is going to grow and is going to need that complexity in the future. But this is it is pretty much like, you don't need to have a complex application to need or consider using a state management solution or a store. That what defines what defines if you should or not use a state management solution is how the store is used inside of your application. For example, is your state used in many different places in pages or does your state out these pages? Do you need your state when you go from one page to another? Maybe your application only has three pages, but you require that, um, state to out leaves all the pages. And in that scenario you need a state management. And then the next question that comes to your mind, to to my mind is should I stop to, uh, should I stop having that bare bones reactive global state management solution or should I use a store? And the truth is there is a very small step to get to use a store. You just need using defined store with PNIA or UX5 and you can pretty much keep the same things that you were having. The state is going to be in a vertical state. Then you're going to have, uh, the global state variable is going to become these. So equals something. So the change is very simple. And the cost in terms of size, it also, uh, very small is like 1.5 kilobytes for PNIA. Um, but of course it comes with many other things, right? So do you really need a store? What makes you change your mind? What it means to go from, okay, I'm going to stop using my variable in solution and start using a store.
And there are a few reasons that will make you go that direction. The main reason is server side rendering, uh, is definitely so much easier to handle with the store like PNIA or Vuex, um, but there are many more, so you also have state outletting components. Uh, this is pretty much thumbs out of the box for the state management solutions as well. But, uh, depending on how and where you want to instance it, the global state is not something that always comes in. And then you have the centralized state shared by many components. So, if you create one single global state, that's not going to scale forever.
Comments