-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Labels
v3possible v3.0.0 featurespossible v3.0.0 features
Description
// these are the only 4 exports (no more Detector)
import { Online, Offline, useOnline, useOnlineEffect } from "react-detect-offline";
function Demo () {
// demo the 4 interfaces provided by react-detect-offline
const online = useOnline({
polling: {
enabled: true,
url: "https://...",
timeout: 3000,
interval: 8000,
},
// ... any other future options
});
useOnlineEffect(online => {
console.log("Connection change!");
console.log(`You are now ${online ? "online" : "offline"}`);
}, {
polling: false
})
return (
<div className={online ? "main" : "warning"}>
Some text
<Online>Click to refresh</Online>
<Offline>You are currently offline.</Offline>
</div>
);
}Key points:
useOnlineEffectis the CORE functionality. Everything is based on it.useOnlineusesuseOnlineEffectanduseState. It returns a boolean.OnlineandOfflinework exactly as they do in v2, but under the hood useuseOnline- no more
Detector- people could just useuseOnlinehook* - no more
onChangeprop - people could just useuseOnlineEffect* -
- for the deprecations, you could still include them, but recommend people use other things. that way ppl could still upgrade, but you wouldn't break their code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
v3possible v3.0.0 featurespossible v3.0.0 features