Skip to content

refactor: extract a generic useStorageValue hook for localStorage state#163

Open
cleanjunc wants to merge 1 commit into
MkDev11:mainfrom
cleanjunc:refactor/use-storage-value-hook
Open

refactor: extract a generic useStorageValue hook for localStorage state#163
cleanjunc wants to merge 1 commit into
MkDev11:mainfrom
cleanjunc:refactor/use-storage-value-hook

Conversation

@cleanjunc
Copy link
Copy Markdown
Contributor

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, and useSettings are 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

  • Bug fix
  • New feature
  • Enhancement
  • Refactor
  • Documentation
  • Other (describe):

Testing

  • pnpm build passes
  • Manual browser smoke test: toggled repo tracking on the Repositories page, toggled miner tracking on the Miners page, and changed several Settings values (layout, page size, render markdown) with two tabs open to confirm same tab and cross tab updates still propagate
  • N/A, docs / config only

Checklist

  • Self-reviewed the diff
  • Follows existing code patterns and naming
  • No unrelated changes included
  • Documentation updated if behavior changed

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@cleanjunc, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b9122877-89a7-4994-9748-e74d12cbc7b6

📥 Commits

Reviewing files that changed from the base of the PR and between aab5b71 and 13d7ff0.

📒 Files selected for processing (4)
  • src/lib/settings.ts
  • src/lib/tracked-miners.ts
  • src/lib/tracked-repos.ts
  • src/lib/use-storage-value.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Three React hooks reimplement the same localStorage state pattern

1 participant