{"id":24580423,"url":"https://github.com/ichengbo/react-native-error-helper","last_synced_at":"2025-04-24T01:09:51.970Z","repository":{"id":37073779,"uuid":"358886464","full_name":"iChengbo/react-native-error-helper","owner":"iChengbo","description":"A helper for React Native to catch global JS errors and provide some ways to resolve error boundaries.","archived":false,"fork":false,"pushed_at":"2023-02-15T20:59:36.000Z","size":111,"stargazers_count":19,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T01:09:45.818Z","etag":null,"topics":["react-native"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/iChengbo.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":"2021-04-17T13:30:09.000Z","updated_at":"2024-06-11T03:28:53.000Z","dependencies_parsed_at":"2023-02-11T20:30:51.953Z","dependency_job_id":null,"html_url":"https://github.com/iChengbo/react-native-error-helper","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-error-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-error-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-error-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-error-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iChengbo","download_url":"https://codeload.github.com/iChengbo/react-native-error-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250540941,"owners_count":21447427,"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":["react-native"],"created_at":"2025-01-24T01:54:07.986Z","updated_at":"2025-04-24T01:09:51.956Z","avatar_url":"https://github.com/iChengbo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-error-helper\n\n\u003e A helper for React Native to catch global JS errors and provide some ways to resolve error boundaries.\n\n\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)\n[![npm-version](https://img.shields.io/npm/v/react-native-error-helper)](https://www.npmjs.com/package/react-native-error-helper)\n[![npm](https://img.shields.io/npm/dm/react-native-error-helper.svg)](https://www.npmjs.com/package/react-native-error-helper)\n[![](https://img.shields.io/github/release-date/iChengbo/react-native-error-helper)](https://github.com/iChengbo/react-native-error-helper)\n\n\n\u003c!-- [![https://nodei.co/npm/react-native-error-helper.png?downloads=true\u0026downloadRank=true\u0026stars=true](https://nodei.co/npm/react-native-error-helper.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://www.npmjs.com/package/react-native-error-helper) --\u003e\n\n\n## Table of Contents\n- [Install](#Install)\n- [Usage](#Usage)\n  - [setGlobalErrorHandler](#setGlobalErrorHandler)\n  - [setPromiseUnCatchHandler](#setPromiseUnCatchHandler)\n  - [ErrorBoundary](#ErrorBoundary)\n  - [withErrorBoundary](#withErrorBoundary)\n- [LICENSE](#LICENSE)\n\n\n## Install\n\n\u003e yarn add react-native-error-helper\n\n## Usage\n\n### setGlobalErrorHandler\n\n```js\nimport { setGlobalErrorHandler } from 'react-native-error-helper';\n\nsetGlobalErrorHandler((error, isFatal) =\u003e {\n  console.log('global error：', error, isFatal);\n}, true);\n```\n\n### setPromiseUnCatchHandler\n\n```js\nimport { setPromiseUnCatchHandler } from 'react-native-error-helper';\n\nsetPromiseUnCatchHandler((id, err) =\u003e {\n  console.log('promise un catch：', err);\n}, true);\n```\n\n### ErrorBoundary\n\n```js\nimport { ErrorBoundary } from 'react-native-error-helper';\n\nconst App = () =\u003e (\n  \u003cErrorBoundary\u003e\n    \u003cBugComponent /\u003e\n  \u003c/ErrorBoundary\u003e\n)\n```\n\n### withErrorBoundary\n\n#### class component\n\n```js\nimport { withErrorBoundary } from 'react-native-error-helper';\n\n@withErrorBoundary({\n  renderBoundary: ({error}) =\u003e {\n    return \u003cText\u003ecatch error: {error.message}\u003c/Text\u003e;\n  },\n})\nclass BugCenter extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      isError: false,\n    };\n  }\n\n  render() {\n    const {isError} = this.state;\n    if (isError) {\n      throw new Error('💥');\n    } else {\n      return (\n        \u003cText\n          onPress={() =\u003e {\n            this.setState({\n              isError: true\n            });\n          }}\u003e\n          {String(isError)}\n        \u003c/Text\u003e\n      );\n    }\n  }\n}\n```\n#### function component\n\n```js\nimport { withErrorBoundary } from 'react-native-error-helper';\n\nconst BugCenter = props =\u003e {\n  const [isError, setIsError] = useState();\n  if (isError) {\n    throw new Error('💥');\n  } else {\n    return (\n      \u003cText\n        onPress={() =\u003e {\n          this.setState({\n            isError: true\n          });\n        }}\u003e\n        {String(isError)}\n      \u003c/Text\u003e\n    )\n  }\n}\n\nconst SafeCenter = withErrorBoundary({\n  renderBoundary: ({error}) =\u003e {\n    return \u003cText\u003ecatch error: {error.message}\u003c/Text\u003e;\n  },\n})(BugCenter);\n```\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichengbo%2Freact-native-error-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichengbo%2Freact-native-error-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichengbo%2Freact-native-error-helper/lists"}