{"id":13475129,"url":"https://github.com/bamlab/redux-enhancer-react-native-appstate","last_synced_at":"2025-06-26T03:05:14.518Z","repository":{"id":18738899,"uuid":"85181772","full_name":"bamlab/redux-enhancer-react-native-appstate","owner":"bamlab","description":"Connect your App State changes directly to your Redux store","archived":false,"fork":false,"pushed_at":"2023-01-12T06:49:03.000Z","size":256,"stargazers_count":90,"open_issues_count":10,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T08:51:22.538Z","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":"mit","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-03-16T10:11:38.000Z","updated_at":"2023-09-07T07:15:57.000Z","dependencies_parsed_at":"2023-01-14T12:54:30.171Z","dependency_job_id":null,"html_url":"https://github.com/bamlab/redux-enhancer-react-native-appstate","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bamlab/redux-enhancer-react-native-appstate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-appstate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-appstate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-appstate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-appstate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bamlab","download_url":"https://codeload.github.com/bamlab/redux-enhancer-react-native-appstate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamlab%2Fredux-enhancer-react-native-appstate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261990350,"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":"2024-07-31T16:01:17.599Z","updated_at":"2025-06-26T03:05:14.490Z","avatar_url":"https://github.com/bamlab.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# redux-enhancer-react-native-appstate\nConnect your App State changes directly to your Redux store!\n\n## Installation\n\n```\nnpm install --save redux-enhancer-react-native-appstate\n```\n\n## Usage\n\nWhen you create your Redux store, add the enhancer:\n\n```javascript\nimport { createStore } from 'redux';\nimport applyAppStateListener from 'redux-enhancer-react-native-appstate';\n\n...\n\nconst store = createStore(reducers, initalState, [\n  applyAppStateListener(),\n]);\n```\n\nThe store will now automatically dispatch app state related actions.\n\nFor instance, you can use it in a reducer:\n```javascript\nimport { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';\n\nfunction reducer(state = '', action) {\n  switch (action.type) {\n    case FOREGROUND:\n      return 'back to foreground';\n    case BACKGROUND:\n      return 'background';\n    case INACTIVE:\n      return 'inactive';\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, composeEnhancers(\n  applyAppStateListener(),\n  applyMiddleware(sagaMiddleware)\n));\n\n// bad\nconst store = createStore(reducers, initalState, composeEnhancers(\n  applyMiddleware(sagaMiddleware),\n  applyAppStateListener()\n));\n```\n\nThen you can define a saga like:\n\n```javascript\nimport { takeLatest } from 'redux-saga/effects';\nimport { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';\n\nfunction* appHasComeBackToForeground() {\n  // app has come back to foreground!\n}\n\nfunction* watchForAppBackToForeground() {\n  yield takeLatest(\n    FOREGROUND,\n    catchApiExceptions(appHasComeBackToForeground),\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-appstate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbamlab%2Fredux-enhancer-react-native-appstate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamlab%2Fredux-enhancer-react-native-appstate/lists"}