refactor: extract a generic useStorageValue hook for localStorage state#163
refactor: extract a generic useStorageValue hook for localStorage state#163cleanjunc wants to merge 1 commit into
Conversation
|
Warning Review limit reached
More reviews will be available in 22 minutes and 40 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds
src/lib/use-storage-value.ts, a generic hook that encapsulates the localStorage read, write, parse, serialize, and cross tab event subscription pattern that was previously duplicated across three files.useTrackedRepos,useTrackedMiners, anduseSettingsare now thin wrappers around it.The public hook APIs and the custom event names (
tracked-repos-changed,tracked-miners-changed,settings-changed) are unchanged, so no call sites needed to be touched. The wrappers preserve the original behavior of always reflecting the parsed disk value after a write (toggle and update still re read from localStorage so rapid successive writes do not race).Related Issues
Closes #162
Type of Change
Testing
pnpm buildpassesChecklist