{"id":29023040,"url":"https://github.com/bamlab/redux-enhancer-react-native-network","last_synced_at":"2025-06-26T03:05:12.453Z","repository":{"id":57350619,"uuid":"107542547","full_name":"bamlab/redux-enhancer-react-native-network","owner":"bamlab","description":"Connect redux to the network changes","archived":false,"fork":false,"pushed_at":"2020-01-20T16:07:14.000Z","size":5,"stargazers_count":10,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-21T18:19:08.096Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bamlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-19T12:22:18.000Z","updated_at":"2022-02-26T17:46:18.000Z","dependencies_parsed_at":"2022-09-16T21:12:52.070Z","dependency_job_id":null,"html_url":"https://github.com/bamlab/redux-enhancer-react-native-network","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bamlab/redux-enhancer-react-native-network","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bamlab","download_url":"https://codeload.github.com/bamlab/redux-enhancer-react-native-network/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-network/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261990349,"owners_count":23241188,"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":[],"created_at":"2025-06-26T03:05:11.849Z","updated_at":"2025-06-26T03:05:12.432Z","avatar_url":"https://github.com/bamlab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-enhancer-react-native-network\nConnect redux to the network changes\n\n## Installation\n\n```\nnpm install --save redux-enhancer-react-native-network\n```\n\n## Usage\n\nWhen you create your Redux store, add the enhancer:\n\n```javascript\nimport { createStore } from 'redux';\nimport applyNetworkListener from 'redux-enhancer-react-native-network';\n\n...\n\nconst store = createStore(reducers, initalState, [\n  applyNetworkListener(),\n]);\n```\n\nThe store will now automatically dispatch an action:\n\n```javascript\n{\n  type: STATUS_CHANGED,\n  payload: {\n    isConnected: boolean\n  }\n}\n```\n\nFor instance, you can use it in a reducer:\n```javascript\nimport { STATUS_CHANGED } from 'redux-enhancer-react-native-network';\n\nfunction reducer(state = '', action) {\n\n  switch (action.type) {\n    case STATUS_CHANGED:\n      return action.payload.isConnected ?  'you are connected' : 'you are not connected';\n    default:\n      return state\n  }\n}\n```\n\n### Usage with Redux Saga\n\nMake sure that this enhancer is applied before the saga middleware.\nOtherwise, your saga would not be able to intercept the actions.\n\n```javascript\n// good\nconst store = createStore(reducers, initalState, [\n  applyNetworkListener(),\n  applyMiddleware(sagaMiddleware),\n]);\n\n// bad\nconst store = createStore(reducers, initalState, [\n  applyMiddleware(sagaMiddleware),\n  applyNetworkListener(),\n]);\n\n// good (with compose)\nconst enhancers = [applyNetworkListener(), applyMiddleware(...middlewares)];\n\nconst store = () =\u003e {\n  let store = createStore(persistedReducer, compose(...enhancers));\n  return { ...store, runSaga: sagaMiddleware.run };\n};\n```\n\nThen you can define a saga like:\n\n```javascript\nimport { takeLatest } from 'redux-saga/effects';\nimport { STATUS_CHANGED } from 'redux-enhancer-react-native-network';\n\nfunction* connectionStatusHasChanged() {\n  // app connection status has changed\n}\n\nfunction* watchForConnectionStatusChange() {\n  yield takeLatest(\n    STATUS_CHANGED,\n    catchApiExceptions(connectionStatusHasChanged),\n  );\n}\n```\n\n## Contributing\n\nSee [our contributing guidelines](https://bamlab.github.io/open-source/#contributing)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamlab%2Fredux-enhancer-react-native-network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbamlab%2Fredux-enhancer-react-native-network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamlab%2Fredux-enhancer-react-native-network/lists"}