Closed PeterBlenessy closed 1 week ago
The Pinia store implemented is wrong.
This is an example of a good implementation:
import { ref, watch } from "vue"; import { defineStore } from "pinia";
export const usePersistedStore = defineStore("persisted-store", () => {
const apiKey = ref(loadStateFromLocalStorage("apiKey") || ""); function saveStateToLocalStorage(key, value) { localStorage.setItem(key, JSON.stringify(value)); } function loadStateFromLocalStorage(key) { const value = localStorage.getItem(key); return value ? JSON.parse(value) : null; } watch(apiKey, (newValue) => { saveStateToLocalStorage("apiKey", newValue); }); return { apiKey, };
});
Also, rename the application store from index.js to settings-store.js
Also, rename the folder src/store to src/stores
The Pinia store implemented is wrong.
This is an example of a good implementation:
import { ref, watch } from "vue"; import { defineStore } from "pinia";
export const usePersistedStore = defineStore("persisted-store", () => {
});