项目作者: AliYmn

项目描述 :
react navigator onLine
高级语言: JavaScript
项目地址: git://github.com/AliYmn/react-navigator-online.git
创建时间: 2020-02-23T20:14:05Z
项目社区:https://github.com/AliYmn/react-navigator-online

开源协议:MIT License

下载


React Navigator Online

Hi, this package easy to use navigator online. Thanks to this package, you can check internet connection to something or to show popup about internet connection etc.

Note : I used React Hooks.

Demo

now Try right now! on netlify.



Netlify Status


Demo Image

Installation

  1. npm install react-navigator-online
  2. yarn add react-navigator-online

Example

  1. import React from 'react';
  2. import NavigatorOnline from 'react-navigator-online'
  3. // i want to show it with toastify.
  4. import { ToastContainer, toast } from 'react-toastify';
  5. import 'react-toastify/dist/ReactToastify.css';
  6. class Example extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. message_online: "now! you have an internet connection.",
  11. message_ofline: "now! you have no internet connection.",
  12. };
  13. }
  14. showMessage(status) {
  15. if (status) {
  16. toast.success(this.state.message_online)
  17. }
  18. else {
  19. toast.error(this.state.message_ofline)
  20. }
  21. }
  22. render() {
  23. return (
  24. <div>
  25. <center>
  26. <h1>Hello to everyone!</h1>
  27. <h3>We will try react-navigator-online package</h3>
  28. <h3>@Author : Ali Yaman</h3>
  29. </center>
  30. <ToastContainer
  31. position="bottom-left"
  32. autoClose={5000}
  33. hideProgressBar={false}
  34. newestOnTop={false}
  35. closeOnClick
  36. rtl={false}
  37. pauseOnVisibilityChange
  38. draggable
  39. pauseOnHover
  40. onClose={() => alert("ok")}
  41. />
  42. {/* we can get status this onChange function like this. */}
  43. <NavigatorOnline onChange={(status) => this.showMessage(status)} />
  44. </div>
  45. );
  46. }
  47. }
  48. export default Example;