Created
December 5, 2025 11:56
-
-
Save nodomw/21d0e273dd26c2cd27c77e62f4482151 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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