1.0.4 • Published 4 years ago

react-slack-notification v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

react-slack-notification

React Slack Notification is a lightweight package, Send messages to a Slack channel directly from your react app.

Node version NPM JavaScript Style Guide

Install

npm install --save react-slack-notification

OR

yarn add react-slack-notification

Usage

Send your error logs directly to the slack channel without third party integration.

import notifyToSlackChannel from 'react-slack-notification';

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError(error) {
    // Update state so the next render will show the fallback UI.
    return { hasError: true };
  }

  componentDidCatch(error, errorInfo) {
    // Log the error to a slack channel
    notifyToSlackChannel('https://hooks.slack.com/services/xxxxxxxxxxxxx/example/webhook', error);
  }

  render() {
    if (this.state.hasError) {
      // You can render any custom fallback UI
      return <h1>Something went wrong.</h1>;
    }

    return this.props.children;
  }
}

Override Channel, Username, Bot Icon

notifyToSlackChannel(webhook,message,#channel/@username,username,botIconURL);

webhook: Generate using incoming Webhook

message: Text to notify

#channel/@username: Override the channel in Webhook or Direct message to a user in your workspace

username: Message will be displayed using this name

botIconURL: Message bot icon

Sample Message

License

The MIT License (MIT). Please see License File for more information.

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago