Skip to content

feat(hooks): add SSR-safe useMediaQuery + breakpoint helpers (#437)#455

Open
almuslavish wants to merge 1 commit into
CredenceOrg:mainfrom
almuslavish:feat/use-media-query-hook
Open

feat(hooks): add SSR-safe useMediaQuery + breakpoint helpers (#437)#455
almuslavish wants to merge 1 commit into
CredenceOrg:mainfrom
almuslavish:feat/use-media-query-hook

Conversation

@almuslavish

@almuslavish almuslavish commented Jun 28, 2026

Copy link
Copy Markdown

closes #437

Summary

Implements #437.

Adds a typed, SSR-safe useMediaQuery hook that centralizes matchMedia subscriptions, removes the need for scattered inline calls, and enables JS-driven responsive component behavior alongside the existing CSS reflow.

Changes

src/hooks/useMediaQuery.ts (new)

  • useMediaQuery(query: string): boolean — subscribes to any CSS media query, cleans up the listener on unmount, returns false when window / matchMedia is unavailable (SSR-safe).
  • useIsMobile(): boolean — named breakpoint helper at the repo-documented 768 px threshold ((max-width: 767px)).
  • Mirrors the addEventListener / removeEventListener pattern from SettingsContext.
  • Lazy useState initializer reads the initial match synchronously — no flash of wrong state.

src/pages/TrustScore.tsx

  • Imports and calls useIsMobile.
  • Drives the "Recent Activity" card heading: mobile → Recent Activity, desktop → Recent Activity Timeline.

src/hooks/useMediaQuery.test.ts (new)

Vitest tests covering:

  • No-window / no-matchMedia guard (returns false, no crash)
  • Initial match false / true
  • Change-event-driven re-render
  • Listener cleanup on unmount
  • Re-subscription when query string changes
  • useIsMobile breakpoint value and query string assertion

docs/HOOKS.md

  • Added useMediaQuery / useIsMobile to the Contents list.
  • Full section (signature, params, behavior notes, usage example) inserted before useReducedMotion.

Acceptance criteria

Requirement Status
useMediaQuery + breakpoint helpers implemented
Listener cleanup + no-window guard
Used in at least one real surface (TrustScore activity panel heading)
Vitest coverage: initial value, change events, cleanup, re-subscription
Follows existing matchMedia listener pattern (SettingsContext)
TypeScript strict
HOOKS.md updated

Centralizes matchMedia subscriptions and uses it to adapt the Trust Score
activity panel at the mobile breakpoint.

- useMediaQuery(query): SSR-safe, listener-cleaned-up boolean hook
- useIsMobile(): shorthand for (max-width: 767px) threshold
- TrustScore: switch activity card heading between 'Recent Activity'
  (mobile) and 'Recent Activity Timeline' (desktop)
- Vitest tests: no-window guard, initial value, change events, cleanup,
  query re-subscription, useIsMobile query string
- HOOKS.md: document useMediaQuery and useIsMobile

Closes CredenceOrg#437
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@almuslavish Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add a useMediaQuery hook and drive the Bond/Trust two-column grids off a JS breakpoint

1 participant