useLocalStorage
A ref mirrored to localStorage as JSON, with an optional Zod schema: anything that does not parse falls back to the default. A change made in another tab reaches this one through the storage event, checked against the same schema.
Install: pnpm add-composable useLocalStorage
Persistent todo list
Arrays are automatically serialized and deserialized. Add some tasks, check them off, and then refresh the page to see them persist seamlessly.
API
key(string): The localStorage key to read from and write to.defaultValue(T): The fallback value used if the key does not exist or if JSON parsing fails.schema(ZodType<T>): Optional Zod schema to validate stored data. Invalid data triggers the fallback defaultValue.