React6 min read

React Progressive Web App

Convert React app to Progressive Web App.

Sarah Johnson
December 20, 2025
0.0k0

Make your React app work offline as a PWA.

Create PWA Template

npx create-react-app my-app --template cra-template-pwa

Register Service Worker

// index.js
import * as serviceWorkerRegistration from './serviceWorkerRegistration';

serviceWorkerRegistration.register();

manifest.json

{
  "short_name": "MyApp",
  "name": "My React App",
  "icons": [
    {
      "src": "icon-192.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ],
  "start_url": ".",
  "display": "standalone",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}

Offline Detection

function useOnlineStatus() {
  const [isOnline, setIsOnline] = useState(navigator.onLine);

  useEffect(() => {
    const handleOnline = () => setIsOnline(true);
    const handleOffline = () => setIsOnline(false);

    window.addEventListener('online', handleOnline);
    window.addEventListener('offline', handleOffline);

    return () => {
      window.removeEventListener('online', handleOnline);
      window.removeEventListener('offline', handleOffline);
    };
  }, []);

  return isOnline;
}

Remember

  • Works offline
  • Installable on mobile
  • Add to home screen
  • Requires HTTPS

Next: Learn GraphQL!

#React#PWA#Offline#Advanced