0Pricing
Frontend Academy · Lesson

Pinia for Vue: defineStore and storeToRefs

Define a Pinia store with defineStore, access it in components, use storeToRefs to keep reactivity when destructuring state.

What Is Pinia?

Pinia is the official state management library for Vue 3. It replaces Vuex with a simpler, type-safe, DevTools-integrated API that feels like Composition API.

Installing Pinia

Install and register the Pinia plugin with the Vue app.

npm install pinia

// main.ts
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './App.vue';

const app = createApp(App);
app.use(createPinia());
app.mount('#app');

All lessons in this course

  1. Redux Toolkit: createSlice and configureStore
  2. Zustand for Lightweight React State
  3. Pinia for Vue: defineStore and storeToRefs
  4. When to Use Global vs Local State
← Back to Frontend Academy