Menu

πŸš€ New React Challenge: Build an External Store
πŸ“°

πŸš€ New React Challenge: Build an External Store

DEV Community: reactΒ·ReactChallengesΒ·about 9 hours ago
#GwbJEdxN
#devtoreact#devto#dev#store#polling
Reading 0:00
15s threshold

Most React apps reach for a state library the moment state has to live outside a component. Building one yourself is the fastest way to understand what useSyncExternalStore actually expects β€” and why a store that returns a fresh object on every getSnapshot call loops forever.

🧩 Overview

Build the external store behind a live metrics dashboard: immutable snapshots, subscribe / getSnapshot , five-second polling, stale-response protection, and pause/resume with real cleanup β€” all in store.ts .

πŸ‘‰ https://www.reactchallenges.com/challenges/build-external-store

βœ… Requirements

createMetricsStore(fetcher) returns subscribe , getSnapshot , start , refresh , pause , and resume ; fetcher defaults to fetchMetrics .

The initial snapshot is { metrics: [], updatedAt: null, status: "idle", error: null } .

getSnapshot returns the same object reference until the state changes.

subscribe(listener) registers a listener and returns a function that removes it.

Subscribers are notified after every state change.

start()…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.