N
Nuxt6mo ago
Bazze

Pinia and useState

Im building a new store, and remembered the newish useState composable. Normally i would use ref in a Pinia store, but since useState is described in the docs as useState is an SSR-friendly ref replacement. Should i then use useState within the Pinia store? Havent been able to find anyone else asking this question. Im specifically using setup stores.
3 Replies
pyplacca
pyplacca6mo ago
Stack Overflow
Nuxt 3 - Pinia Vs useState()
Store (Pinia) Vs UseState If I am not mistaken, useState can replace any store like Pinia? Given that useState makes ref sharable across all components I have a hard time knowing if I should use a ...
Bazze
Bazze6mo ago
The question is if is should use The vue vanilla way with ref inside the pinia store
export default defineStore("currentUserStore", () => {
const user = ref(null);

return {
user,
};
});
export default defineStore("currentUserStore", () => {
const user = ref(null);

return {
user,
};
});
Or if i should use useState
export default defineStore("currentUserStore", () => {
const user = useState(null);

return {
user,
};
});
export default defineStore("currentUserStore", () => {
const user = useState(null);

return {
user,
};
});
The guy in that question asks if they should either use Pinia or useState
pyplacca
pyplacca6mo ago
There’s no point in using a global state manager insider another global state manager Can you give an example? I don’t think you got my point Exactly The second example to be precise Yeah. Phrasing might’ve been confusing No worries
Want results from more Discord servers?
Add your server