$ recombobulate _
home / tips / extract-pinia-stores-from-bloated-vue-components
0

Extract Pinia Stores from Bloated Vue Components

bagwaa @bagwaa · Mar 26, 2026 · Workflows
extract-pinia-stores-from-bloated-vue-components

If your Vue components are full of repetitive ref() declarations and inline fetch() calls, ask Claude to extract them into a proper Pinia store — it handles the refactor and updates the component in one go.

"This Vue component has 80+ lines of data fetching and local state.
Extract everything into a Pinia store:
- Move all refs and reactive state to the store's state()
- Convert fetch logic into store actions with loading/error states
- Add a $reset() action for testing
- Update the component to use storeToRefs() for reactivity
- Write Vitest tests that use createPinia() and mock the API calls"

Claude generates a typed store and rewrites the component to stay lean — it should only call store actions and render:

// store/useUsersStore.ts
export const useUsersStore = defineStore('users', () => {
  const users = ref<User[]>([])
  const loading = ref(false)
  const error = ref<string | null>(null)

  async function fetchUsers() { /* ... */ }
  function $reset() { users.value = []; error.value = null }

  return { users, loading, error, fetchUsers, $reset }
})

It also handles the subtle bits: resetting state between route navigations, preventing duplicate concurrent fetches with a guard, and setting up a storeToRefs() pattern so reactivity doesn't silently break when you destructure.

Fat components are a maintenance problem — Pinia stores keep your data layer testable and your templates readable.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 2 hours ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 2 hours ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago