use-online-checking 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Premanshu Ray
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # useOnline
2
+
3
+ A simple and lightweight custom React hook to detect browser online and offline status in real-time.
4
+
5
+ ---
6
+
7
+ ## ✨ Features
8
+
9
+ - 🚀 Lightweight and dependency-free
10
+ - ⚡ Real-time network status detection
11
+ - 🔄 Automatic event listener cleanup
12
+ - 🧠 Easy to use in any React project
13
+
14
+ ---
15
+
16
+ ## 📦 Installation
17
+
18
+ If published to npm:
19
+
20
+ ```bash
21
+ npm install use-online
22
+ ```
23
+
24
+ Or clone the repository:
25
+
26
+ ```bash
27
+ git clone https://github.com/your-username/use-online.git
28
+ ```
29
+
30
+ ---
31
+
32
+ ## 🚀 Usage
33
+
34
+ ```jsx
35
+ import useOnline from "use-online";
36
+
37
+ function App() {
38
+ const isOnline = useOnline();
39
+
40
+ return (
41
+ <div>
42
+ {isOnline ? (
43
+ <h2>✅ You are Online</h2>
44
+ ) : (
45
+ <h2>❌ You are Offline</h2>
46
+ )}
47
+ </div>
48
+ );
49
+ }
50
+
51
+ export default App;
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 🧠 How It Works
57
+
58
+ The hook listens to browser events:
59
+
60
+ - `window.addEventListener("online")`
61
+ - `window.addEventListener("offline")`
62
+
63
+ When the network status changes, the state updates automatically.
64
+
65
+ ---
66
+
67
+ ## 📌 API
68
+
69
+ ### `useOnline()`
70
+
71
+ Returns:
72
+
73
+ | Name | Type | Description |
74
+ |-----------|---------|---------------------------------|
75
+ | isOnline | boolean | Current internet connection status |
76
+
77
+ ---
78
+
79
+ ## 📁 Project Structure
80
+
81
+ ```
82
+ use-online/
83
+
84
+ ├── src/
85
+ │ ├── useOnline.js
86
+ │ ├── App.jsx
87
+ │ ├── main.jsx
88
+
89
+ ├── package.json
90
+ ├── README.md
91
+ └── vite.config.js
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 🤝 Contributing
97
+
98
+ Contributions are welcome.
99
+ Feel free to open issues or submit pull requests.
100
+
101
+ ---
102
+
103
+ ## 📄 License
104
+
105
+ MIT
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "use-online-checking",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight React hook to detect online/offline network status in real time.",
5
+ "main": "src/index.js",
6
+ "keywords": [
7
+ "react",
8
+ "react-hook",
9
+ "custom-hook",
10
+ "network",
11
+ "online",
12
+ "offline"
13
+ ],
14
+ "peerDependencies": {
15
+ "react": ">=16.8"
16
+ },
17
+ "author": {
18
+ "name": "Premanshu Ray",
19
+ "email" : "premanshuray981@gmail.com",
20
+ "url": "https://github.com/Prem-Ray"
21
+ },
22
+ "license": "MIT"
23
+ }
@@ -0,0 +1,26 @@
1
+ import { useState , useEffect} from "react"
2
+
3
+ const useOnline = ()=>{
4
+ const [isOnline,setIsOnline] = useState(true) ;
5
+
6
+ useEffect(()=>{
7
+ const checkOnline = ()=>{
8
+ setIsOnline(true) ;
9
+ }
10
+ const checkOffline = ()=>{
11
+ setIsOnline(false) ;
12
+ }
13
+ window.addEventListener('online',checkOnline)
14
+
15
+ window.addEventListener('offline',checkOffline)
16
+
17
+ return ()=>{
18
+ window.removeEventListener("online",checkOnline) ;
19
+ window.removeEventListener("offline",checkOffline) ;
20
+ }
21
+ },[])
22
+
23
+ return isOnline ;
24
+ }
25
+
26
+ export default useOnline ;