ecosystem/pinia-prefer-store-to-refs
Prefer storeToRefs() when destructuring Pinia stores.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
ecosystem |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
Destructuring name directly from the store separates the value from its reactive store access.
<script setup lang="ts">
const { name } = useUserStore();
</script>
Good
The store remains intact and storeToRefs creates a reactive reference for name.
<script setup lang="ts">
const store = useUserStore();
const { name } = storeToRefs(store);
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"ecosystem/pinia-prefer-store-to-refs": "warn"
}
},
});
Then run vp run lint.