https://github.com/cusspvz/intl-error
react-intl/intl compatible error
https://github.com/cusspvz/intl-error
error error-handling errors intl react react-intl react-native
Last synced: 11 months ago
JSON representation
react-intl/intl compatible error
- Host: GitHub
- URL: https://github.com/cusspvz/intl-error
- Owner: cusspvz
- License: eupl-1.1
- Created: 2017-03-16T11:00:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-16T20:08:14.000Z (almost 9 years ago)
- Last Synced: 2025-03-26T09:51:10.973Z (12 months ago)
- Topics: error, error-handling, errors, intl, react, react-intl, react-native
- Language: JavaScript
- Size: 28.3 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# intl-error
react-intl/intl compatible error
Handle better your errors, add intl compatible errors to your webapp actions.
## Installation
```bash
yarn add intl-error
```
## Usage
```javascript
import React, { Component } from 'react'
import IntlError from 'intl-error'
import { injectIntl } from 'react-intl'
function doSomething () {
throw new IntlError({ id: 'testing' })
}
@injectIntl
export default class TestComponent extends Component {
state = { error: undefined }
render () {
const { state: { error }, props: { intl }, onClick } = this
return (
{error && error.formatMessage(intl)}
)
}
onClick = async () => {
try {
doSomething()
} catch (error) {
await this.setState({ error })
}
}
}
```