Skip to main content

Migration from v1.x to v2.0.0

Breaking Changes

1. setItem is now async

v1.x

storage.setItem('key', value); // void — fire and forget

v2.0.0

await storage.setItem('key', value); // Promise<void> — awaitable

Errors in v1.x were silently swallowed. In v2.0.0, errors propagate to the caller unless you configure onError: 'silent'.


2. getItem no longer uses a callback

v1.x

storage.getItem('key', (item) => {
if (item) console.log(item);
});

v2.0.0

const item = await storage.getItem('key');
if (item) console.log(item);

New Features in v2.0.0

FeatureHow to use
Batch writeawait storage.setItems({ a: 1, b: 2 })
Batch readawait storage.getItems(['a', 'b'])
Read allawait storage.getAll()
Cache patternawait storage.getOrSet(key, factory)
Check existencestorage.has(key)
Purge expiredstorage.removeExpired()
Reset TTLstorage.updateExpiry(key)
Item countstorage.size()
Namespacenew ValiStorages({ prefix: 'app' })
Sliding TTLnew ValiStorages({ slidingExpiration: true })
Error controlnew ValiStorages({ onError: 'silent' })
Cross-tab syncnew ValiStorages({ onChange: (key, val) => {} })
Type-safe APIcreateTypedStorage<Schema>()
SSR checkValiStorages.isAvailable()
Cleanupstorage.destroy()

Migration Checklist

  • Add await before every setItem call
  • Replace getItem(key, callback) with const val = await getItem(key)
  • Wrap instantiation in useEffect or guard with ValiStorages.isAvailable() for SSR projects
  • Consider switching to createTypedStorage<Schema>() for type safety
  • Consider adding prefix to avoid key collisions between instances