Skip to content

Instantly share code, notes, and snippets.

@nodomw
Created December 5, 2025 11:56
Show Gist options
  • Select an option

  • Save nodomw/21d0e273dd26c2cd27c77e62f4482151 to your computer and use it in GitHub Desktop.

Select an option

Save nodomw/21d0e273dd26c2cd27c77e62f4482151 to your computer and use it in GitHub Desktop.
import { useState, useEffect } from "react";
function Indicator() {
const [online, setOnline] = useState(
navigator.onLine,
);
useEffect(() => {
const timer = setTimeout(
setOnline,
1000,
navigator.onLine,
);
return () => clearInterval(timer);
}, [online]);
return (
<div>
{online ? "🟢 Online" : "🔴 Offline"}
</div>
);
}
export default Indicator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment