{"id":20614779,"url":"https://github.com/dashed/react-offline","last_synced_at":"2025-04-15T07:34:59.745Z","repository":{"id":49553335,"uuid":"103026901","full_name":"dashed/react-offline","owner":"dashed","description":"React component that notifies when browser is either offline or online.","archived":false,"fork":false,"pushed_at":"2021-10-18T20:25:28.000Z","size":464,"stargazers_count":10,"open_issues_count":12,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T13:01:39.089Z","etag":null,"topics":["offline","online","react"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dashed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-10T12:16:52.000Z","updated_at":"2023-03-04T05:17:56.000Z","dependencies_parsed_at":"2022-09-26T16:32:19.012Z","dependency_job_id":null,"html_url":"https://github.com/dashed/react-offline","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-offline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-offline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-offline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-offline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashed","download_url":"https://codeload.github.com/dashed/react-offline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249027357,"owners_count":21200616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["offline","online","react"],"created_at":"2024-11-16T11:13:35.512Z","updated_at":"2025-04-15T07:34:59.709Z","avatar_url":"https://github.com/dashed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-offline [![Build Status](https://travis-ci.org/dashed/react-offline.svg)](https://travis-ci.org/dashed/react-offline) [![npm version](https://img.shields.io/npm/v/react-offline.svg?style=flat)](https://www.npmjs.com/package/react-offline)\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/dashed/react-offline.svg)](https://greenkeeper.io/)\n\n\u003e React component that notifies when browser is either offline or online.\n\n## Install\n\n```sh\nyarn add react-offline\n# or\nnpm install react-offline\n```\n\n## Usage\n\n```js\n// 3rd-party imports\n\nimport ReactDOM from \"react-dom\";\nimport React, { Component } from \"react\";\n\nimport Offline from \"react-offline\";\n\n// function as child component\n\nReactDOM.render(\n  \u003cOffline\n    onChange={({ isOffline, isOnline }) =\u003e console.log({ isOffline, isOnline })}\n  \u003e\n    {({ isOffline, isOnline }) =\u003e {\n      return isOffline ? (\n        \u003cdiv\u003e{\"I am offline\"}\u003c/div\u003e\n      ) : (\n        \u003cdiv\u003e{\"I am online\"}\u003c/div\u003e\n      );\n    }}\n  \u003c/Offline\u003e,\n  mountNode\n);\n\n// render prop\n\nReactDOM.render(\n  \u003cOffline\n    onChange={({ isOffline, isOnline }) =\u003e console.log({ isOffline, isOnline })}\n    render={({ isOffline, isOnline }) =\u003e {\n      return isOffline ? \u003cdiv\u003eI am offline\u003c/div\u003e : \u003cdiv\u003eI am online\u003c/div\u003e;\n    }}\n  /\u003e,\n  mountNode\n);\n```\n\n## Props\n\n### `render` (optional)\n\nAn optional function that is called whenever the browser's network connectivity has changed (e.g. switching between online and offline).\n\nThe `render` function is invoked with an object argument: `({ isOffline, isOnline })`.\n\nIt's expected that `render` function returns a single React element.\nThis has same API semantics as [`React.Component.render()`](https://facebook.github.io/react/docs/react-component.html#render).\n\nIf `render` function is given, it has precedence over any given child component:\n\n```js\n\u003cOffline\n  render={() =\u003e {\n    return \u003cdiv\u003e\"I take precedence over any function as child component.\"\u003c/div\u003e;\n  }}\n\u003e\n  {() =\u003e {\n    return \u003cdiv\u003e\"I will not render.\"\u003c/div\u003e;\n  }}\n\u003c/Offline\u003e\n```\n\n### Function as child component (optional)\n\nSame as `render` prop function (see above).\n\nIf `render` function is not given, then the child component will be invoked as a function.\n\nThe child component function is invoked with an object argument: `({ isOffline, isOnline })`.\n\n```js\n\u003cOffline\u003e\n  {({ isOffline, isOnline }) =\u003e {\n    return isOffline ? \u003cdiv\u003e{\"I am offline\"}\u003c/div\u003e : \u003cdiv\u003e{\"I am online\"}\u003c/div\u003e;\n  }}\n\u003c/Offline\u003e\n```\n\n### `onChange` (optional)\n\nAn optional function that is called whenever the browser's network connectivity has changed (e.g. switching between online and offline).\n\nThe `onChange` function is invoked with an object argument: `({ isOffline, isOnline })`.\n\n# License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Freact-offline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashed%2Freact-offline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Freact-offline/lists"}