twcm-error-modal
v0.2.2
Published
Error Modal for use with TWC public platforms
Downloads
8
Readme
twcm-error-modal
Error module to be used for all TWC platforms.
Installation
yarn add twcm-error-modal
Example Usage
import * as React from 'react';
import ErrorModal from 'twcm-error-modal`
class TWCComponent extends React.Component<{}, { error: Error }> {
constructor() {
super();
this.state = { error: null };
this._closeError = this._closeError.bind(this);
}
public breakingCode(): JSX.Element {
const onError = (e: Error) => this._handleError(e);
willBreak()
.catch(onError);
}
public render(): JSX.Element {
<div>
{ this.breakingCode() }
<ErrorModal
isOpen={ !!this.state.error }
err={ this.state.error }
onClose={ this._clearError }
/>
</div>
}
private _emitError(error: Error): void {
this.setState({ error });
}
private _closeError(): void {
this.setState({ error: null });
}
}
API
customMsg: string - Optional message to display
isOpen: boolean - (required)
err: Error - Full error object to display.
onClose: () => any; - (required) Function to run on modal exit.
customMsg?: string; err?: Error; isOpen: boolean; onClose: () => void;
Testing
- Add some tests in a
*.spec.tsx
file - Run
yarn build
Contributing
- Make some changes
- Update tag in package.json
- Ask james for NPM login info if you don't have one.
- Run
npm publish
(CI doesn't deploy yet) - Commit & push code