An open API service indexing awesome lists of open source software.

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

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 })
}
}
}

```