{"id":16800821,"url":"https://github.com/sudoplz/react-native-connectivity-tracker","last_synced_at":"2025-04-11T00:31:55.134Z","repository":{"id":57336213,"uuid":"149500834","full_name":"SudoPlz/react-native-connectivity-tracker","owner":"SudoPlz","description":"Checks (verifies) wether there's a valid internet connection","archived":false,"fork":false,"pushed_at":"2020-09-16T17:34:30.000Z","size":15,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T13:11:27.441Z","etag":null,"topics":["netinfo","react-native"],"latest_commit_sha":null,"homepage":"","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/SudoPlz.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":"2018-09-19T19:20:47.000Z","updated_at":"2021-03-12T18:13:11.000Z","dependencies_parsed_at":"2022-09-11T08:12:04.880Z","dependency_job_id":null,"html_url":"https://github.com/SudoPlz/react-native-connectivity-tracker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SudoPlz%2Freact-native-connectivity-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SudoPlz%2Freact-native-connectivity-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SudoPlz%2Freact-native-connectivity-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SudoPlz%2Freact-native-connectivity-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SudoPlz","download_url":"https://codeload.github.com/SudoPlz/react-native-connectivity-tracker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322434,"owners_count":21084335,"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":["netinfo","react-native"],"created_at":"2024-10-13T09:35:11.109Z","updated_at":"2025-04-11T00:31:55.110Z","avatar_url":"https://github.com/SudoPlz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## react-native-connectivity-tracker\n\n\n### Why?\nBecause we can no longer trust that react-native connectivity changes are valid, so we have to double check before we trust the result.\nHere's the [RN issue](https://github.com/facebook/react-native/issues/8615)\n\n\n### How?\n\nThe only thing this library does is, whenever a network change event get's dispatched by `NetInfo`, we verify that the connection is alive by pinging google.\n\np.s: On production we verify by checking if our server is up (by overriding `verifyServersAreUp`) but you don't have to do that.\n\n\n### Versions:\n\n- react-native \u003e= 0.58  --\u003e react-native-connectivity tracker \u003e 2.0.0\n- react-native \u003c 0.58  --\u003e react-native-connectivity tracker \u003e 1.0.0\n\n### Installation:\n\n`yarn install react-native-connectivity-tracker`\n\n\n#### Extra steps on if you're using version \u003e= 2.0.0 (not needed if on a previous version)\n\u003cdetails\u003e\n\u003csummary\u003eManually link the library on iOS\u003c/summary\u003e\n\nEither follow the [instructions in the React Native documentation](https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking) to manually link the framework or link using [Cocoapods](https://cocoapods.org) by adding this to your `Podfile`:\n\n```ruby\npod 'react-native-netinfo', :path =\u003e '../node_modules/@react-native-community/netinfo'\n```\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003eManually link the library on Android\u003c/summary\u003e\n\nMake the following changes:\n\n#### `android/settings.gradle`\n```groovy\ninclude ':react-native-community-netinfo'\nproject(':react-native-community-netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')\n```\n\n#### `android/app/build.gradle`\n```groovy\ndependencies {\n   ...\n   implementation project(':react-native-community-netinfo')\n}\n```\n\n#### `android/app/src/main/.../MainApplication.java`\nOn top, where imports are:\n\n```java\nimport com.reactnativecommunity.netinfo.NetInfoPackage;\n```\n\nAdd the `NetInfoPackage` class to your list of exported packages.\n\n```java\n@Override\nprotected List\u003cReactPackage\u003e getPackages() {\n    return Arrays.asList(\n            new MainReactPackage(),\n            new NetInfoPackage()\n    );\n}\n```\n\u003c/details\u003e\n\n### Usage:\n\n```javascript\nimport ConnectivityTracker from 'react-native-connectivity-tracker';\n\nconst onConnectivityChange = (isConnected, timestamp, connectionInfo) =\u003e {\n    console.log(`isConnected: ${isConnected}, when: ${timestamp} more info: ${JSON.stringify(connectionInfo)}`)\n    // connectionInfo is only available if attachConnectionInfo is set to true\n}\n\nConnectivityTracker.init({\n    onConnectivityChange,\n    attachConnectionInfo: false,\n    onError: msg =\u003e console.log(msg),\n    // verifyServersAreUp: () =\u003e store.dispatch(checkOurServersAreUp()),\n});\n```\n    \n\n### Params:\n\n|Key \t| Type \t| Default\t| Definition\t |\n| ---\t| --- \t| ---- \t\t| ----------- \t |\n| **onConnectivityChange**  \t| function(bool, Date, Object)  | -  | This is the main callback you should care about. It get's dispatched whenever there's a connectivity change. |\n| **attachConnectionInfo**   \t| boolean  \t\t\t| false | Attaches more details about the connection on the `onConnectivityChange` callback (3rd param) |\n| **alsoVerifyOnlineStatuses**   \t| boolean  \t\t\t| false | By default we only verify the connectivity whenever we receive an offline status. By turning this on we'll also verify online statuses too. |\n| **dispatchOldEventsToo**   \t| boolean  \t\t\t| false | By default we only dispatch the latest event we received from NetInfo. By turning this on we'll dispatch EVERYTHING. Caution, the order of events is not guaranteed if this is set to true. |\n| **onError** \t\t\t| function  \t\t\t| - | Pass a function here if you want to log errors.   |\n| **verifyServersAreUp**   \t| function \t\t| - | This overrides the default verification method. Feel free to disregard this, unless  want to use your own verification method, instead of relying to google responces. This function can return either a result (true or false) or a Promise  |\n\n\n### Methods:\n\n|Key \t|  Definition\t |\n| ---\t|  ----------- \t |\n| **tryConnection**   | This is a tottally optional method that you can call when you wish to check for a connectivity status on demand. Returnes a promise.|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudoplz%2Freact-native-connectivity-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudoplz%2Freact-native-connectivity-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudoplz%2Freact-native-connectivity-tracker/lists"}