Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thoughts on a hook interface and architecture #71

Open
chrisbolin opened this issue Jan 15, 2021 · 4 comments
Open

Thoughts on a hook interface and architecture #71

chrisbolin opened this issue Jan 15, 2021 · 4 comments
Assignees
Labels
v3 possible v3.0.0 features

Comments

@chrisbolin
Copy link
Collaborator

// 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:

  • useOnlineEffect is the CORE functionality. Everything is based on it.
  • useOnline uses useOnlineEffect and useState. It returns a boolean.
  • Online and Offline work exactly as they do in v2, but under the hood use useOnline
  • no more Detector - people could just use useOnline hook*
  • no more onChange prop - people could just use useOnlineEffect*
    • 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.
@chrisbolin
Copy link
Collaborator Author

forgive my javascript, i haven't written it lately 😂

@cwise89 cwise89 mentioned this issue Mar 2, 2021
@EltonCarreiro
Copy link

That looks pretty good and aligned with the latest React code. :)

@cwise89 cwise89 added the v3 possible v3.0.0 features label May 27, 2021
@tamizharasank
Copy link

I'm getting this error GET https://ipv4.icanhazip.com/ net::ERR_NAME_NOT_RESOLVED (anonymous) on my react app but i'm using stable internet connection only. Please find the below attachement and please help me to solve this.
Screenshot 2021-06-08 131517

@geekskai
Copy link

You can take a look at this, this is the implementation of the reference v3 version https://github.com/geekskai/react-network-detect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 possible v3.0.0 features
Projects
None yet
Development

No branches or pull requests

5 participants