use-online-checking 1.0.0 → 1.0.2
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/README.md +104 -104
- package/index.js +1 -0
- package/package.json +23 -23
package/README.md
CHANGED
|
@@ -1,105 +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/
|
|
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
|
-
|
|
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-checking
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or clone the repository:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/Prem-Ray/use-online-checking.git
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 🚀 Usage
|
|
33
|
+
|
|
34
|
+
```jsx
|
|
35
|
+
import useOnline from "use-online-checking";
|
|
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
105
|
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./src/useOnline.js";
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "use-online-checking",
|
|
3
|
-
"version": "1.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"
|
|
20
|
-
"url": "https://github.com/Prem-Ray"
|
|
21
|
-
},
|
|
22
|
-
"license": "MIT"
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "use-online-checking",
|
|
3
|
+
"version": "1.0.2",
|
|
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
|
+
}
|