Show Online or Offline
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Show whether the app is connected. The component gets a subscribe prop: subscribe(listener) calls listener(true) straight away if online or listener(false) if offline, calls it again on every change, and returns a function that unsubscribes. Subscribe when the component mounts and unsubscribe when it unmounts. Show an element with role="status" reading "You're online" or "You're offline", and a "Sync now" button that is disabled while offline. The starter's default subscribe listens to the browser's online and offline events.
Your code must pass
- Shows what subscribe reports at first
- Updates when the connection changes
- Disables Sync now while offline
- Unsubscribes when unmounted