# 6930 MINLive Dashboard
# 69
30 MIN
Overview
Consume a provided live metrics store with useSyncExternalStore and orchestrate its polling lifecycle, tab visibility, and UI states.
Solution preview
Here's the result you'll build by completing this challenge.
Requirements
- The dashboard reads its data from the provided store with React's
useSyncExternalStorehook (dashboardStore.subscribeanddashboardStore.getSnapshot);store.tsis hidden and must be used as-is. You do not need to write a custom hook. - While the first request is in flight, the status (
data-testid="status") readsUpdating…, the skeleton (data-testid="dashboard-skeleton") is visible, and no metric cards are rendered. - After the first successful response, the status reads
Liveand the dashboard renders four metric cards:data-testid="metric-active-users",metric-revenue,metric-requests, andmetric-error-rate, each showing its value indata-testid="metric-<id>-value". - The last successful update is displayed in
data-testid="last-updated"with the formatUpdated at HH:MM:SS. - Polling starts when the dashboard mounts on a visible document, so the cards update without user interaction.
- While a later poll (automatic or manual) is in flight on a visible document, the status reads
Updating…and returns toLivewhen it succeeds, keeping the current cards on screen instead of the skeleton. - Polling stops when the dashboard unmounts.
- The refresh button (
data-testid="refresh") fetches immediately instead of waiting for the next interval, keeping the previous cards visible while the request is in flight. - The refresh button is disabled while the status is
Updating…. - When a request fails, the status reads
Erroranddata-testid="error-message"contains the failure message. - After a failure, the last successful metric values stay on screen.
- Polling retries on the next interval after a failure. This is handled by the store; no extra retry logic is needed.
- When the document becomes hidden, the status reads
Pausedand no further polling requests are made. - When the document becomes visible again, the dashboard refreshes immediately and resumes polling.
- If the dashboard mounts on a hidden document, it pauses instead of starting, and the status reads
Paused. Callingpause()beforestart()is supported; callingresume()when not paused does nothing.
Notes
- The provided
store.tsis hidden on purpose. It exports thedashboardStoresingleton withsubscribe,getSnapshot,start,refresh,pause, andresume;Components.tsx,data.ts, andtypes.tsare read-only. getSnapshotreturns the current snapshot. Pass it directly touseSyncExternalStore; do not copy the data intouseStateor wrap it in a function that builds a new object.startreturns the cleanup function that stops polling. The effect that starts the dashboard must return it. React StrictMode mounts effects twice in development;startis idempotent, so returning the cleanup is all you need.pauseandresumeown the interval and any request in flight. You only call them; there is nothing to clear or cancel manually in your component.- A manual
refreshcan happen while the interval is still pending. The store discards stale responses, so you never need to stop the interval yourself. pausecan be called beforestart, for example when the dashboard mounts on a hidden document.resumewhen not paused is a no-op.- The Page Visibility API exposes whether the tab is hidden, and the tests simulate that state.
- APIs:
useSyncExternalStore, Page Visibility API.
Tests
- shows the skeleton and the updating status on mount
- renders the four metrics after the first fetch
- shows the time of the last successful update
- polls every five seconds and updates the metrics
- refreshes immediately when the refresh button is clicked
- shows an error and keeps the last successful data
- retries on the next interval after an error
- pauses polling while the tab is hidden
- refreshes and resumes polling when the tab becomes visible
- stops polling when the dashboard unmounts