# 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
useSyncExternalStore(dashboardStore.subscribeanddashboardStore.getSnapshot);store.tsis hidden and must be used as-is. - 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.
- 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.
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. Keep that in mind when an effect starts a timer.
- Pausing is not only about stopping the interval; think about what to do with a request that is already in flight.
- 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