State managment
so guys i have a question. It's about the pinia store and the useState included in nuxt. What's the difference between them and why should I use something like pinia?
2 Replies
Hey there.
I'd say you don't have to use one over the other. The two are really for different use cases. If you want simple, small, SSR safe and reactive state (something like a simple array of user notifications, or a cookie value), you can stick to
useState
.
But as soon as you start doing something like useMyState
that derives values from your simple state (i.e. computed
properties based on state), or that handles manipulating deeply nested state objects, that's when I'd go for Pinia which is really tailored for that sort of things.
Note that if you really don't want to use Pinia you can still use composables and make your own reactive state management using only useState
but at this point you'd be reinventing the wheel that Pinia made for us 🙂There’s a good explanation by @manniL / TheAlexLichter in his video https://youtu.be/mv0WcBABcIk I’d start there.
Alexander Lichter
YouTube
Why you should use useState()
VUEJS AMSTERDAM DISCOUNT (20%): i-really-like-alexander-lichter
🔛 Sending state from the server to the client is tricky but necessary when using SSR. And global state management is not the easiest part of an app either. Nuxt's useState composable solves both of these issues - but how? You'll learn in this weeks video!
Key points:
⏩️ How to se...