@21kb/react-online-status-hook 中文文档教程
@21kb/react-online-status-hook
React hook 订阅
离线/在线
Usage
import {
useOfflineStatus,
useOnlineStatus
} from '@21kb/react-online-status-hook';
const OfflineComponent = () => {
const status = useOfflineStatus();
return <div>You are currently {status ? 'online' : 'offline'}.</div>;
};
const OnlineComponent = () => {
const status = useOnlineStatus();
return <div>You are currently {status ? 'online' : 'offline'}.</div>;
};
事件使用离线在线状态)。
License
麻省理工学院
@21kb/react-online-status-hook
React hook to subscribe to
offline/online
events
Usage
import {
useOfflineStatus,
useOnlineStatus
} from '@21kb/react-online-status-hook';
const OfflineComponent = () => {
const status = useOfflineStatus();
return <div>You are currently {status ? 'online' : 'offline'}.</div>;
};
const OnlineComponent = () => {
const status = useOnlineStatus();
return <div>You are currently {status ? 'online' : 'offline'}.</div>;
};
NOTE: useOfflineStatus
and useOnlineStatus
export the same Hook (useOfflineOnlineStatus
).
License
MIT