@ac-hooks/use-connectivity 中文文档教程
@ac-hooks/use-connectivity
一个自定义 React Hook,使用浏览器的在线/离线事件提供互联网连接状态。
Installation
$ npm i @ac-hooks/use-connectivity
或
$ yarn add @ac-hooks/use-connectivity
Usage
这是基本用法:
import useConnectivity from '@ac-hooks/use-connectivity';
const { isOnline } = useConnectivity();
if (isOnline) {
// you're back!
} else {
// oh no! I can't see you!
}
How to test
您可以在 Network
面板中切换 Offline
复选框来检查它你的开发者工具
。
Live demo
您可以在 CodeSandbox 上查看/编辑上面的示例代码。
Parameters
这个钩子不接受任何参数。
Return
Parameter | Type | Description |
---|---|---|
isOnline | bool | Whether you are online or not |
License
欢迎任何形式的许可贡献!
@ac-hooks/use-connectivity
A custom React Hook that provides internet connectivity status using browsers' online/offline events.
Installation
$ npm i @ac-hooks/use-connectivity
or
$ yarn add @ac-hooks/use-connectivity
Usage
Here is a basic usage:
import useConnectivity from '@ac-hooks/use-connectivity';
const { isOnline } = useConnectivity();
if (isOnline) {
// you're back!
} else {
// oh no! I can't see you!
}
How to test
You can check it toggling the Offline
checkbox in the Network
pane of your developer tools
.
Live demo
You can view/edit the sample code above on CodeSandbox.
Parameters
This hook doesn't accept any parameter.
Return
Parameter | Type | Description |
---|---|---|
isOnline | bool | Whether you are online or not |
License
MIT Licensed
Contributions of any kind welcome!