
Offline-first React without the boilerplate — how I built connectivity-js
Picture this: your user is on a train, editing a doc. Their signal drops. They save. Nothing happens. They reload. Their changes are gone. This happens because most web apps are secretly online-only — they just pretend otherwise. After one too many production incidents where a user lost data, I decided to fix this properly and built connectivity-js — a declarative, type-safe, offline-first connectivity layer for JavaScript and React. The problem with ad-hoc connectivity handling The typical pattern: function SaveButton ({ data }) { const [ isOnline , setIsOnline ] = useState ( navigator . onLine ); useEffect (() => { const up = () => setIsOnline ( true ); const down = () => setIsOnline ( false ); window . addEventListener ( " online " , up ); window . addEventListener ( " offline " , down ); return () => { window . removeEventListener ( " online " , up ); window . removeEventListener ( " offline " , down ); }; }, []); const handleSave = async () => { if ( ! isOnline ) { alert ( " You'r
Continue reading on Dev.to React
Opens in a new tab




