npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crashcatchlib-reactjs

v2.0.10

Published

Receive crash and error reports for JS and ReactJS projects

Downloads

10

Readme

Introduction

The ReactJS CrashCatch library allow you to send both handled and unhandled crashes to the CrashCatch crash monitoring service (https://crashcatch.com).

Installing

The Crash Catch ReactJS library can be installed from NPM using the following command

npm install crashcatchlib-reactjs

Using the Library

Once installed, in your app.js or app.tsx you need to import and the as shown below:

import {CrashCatch, CrashCatchProvider} from "crashcatchlib-reactjs";

Then in the function above the return statement, create a new instance of CrashCatch and initialise the library, using your proejct id, API key and your projects version number as shown below:

const crash_catch = new CrashCatch();
crash_catch.initialiseCrashCatch("<your project id>", "<your projects api key>", "<project version number>");

Then you need to wrap everything in the return of app.js in a and pass the value of a full example of your app.js might look like below:

import React from 'react';
import {BrowserRouter, Routes, Route} from "react-router-dom";
import Home from "./components/Home";
import NotFound from "./components/NotFound";
import ErrorBoundary from "./components/ErrorBoundary";
import {CrashCatch, CrashCatchProvider, CrashCatchContext} from "crashcatchlib-reactjs";

function App() {

    const crash_catch = new CrashCatch();
    crash_catch.initialiseCrashCatch("12345678", "abcdefghijkl", "1.0.0");
  return (

      <CrashCatchProvider value={crash_catch}>
          <ErrorBoundary>
              <BrowserRouter>
                  <Routes>
                      <Route index element={<Home />} />
                      <Route path='*' element={<NotFound />} />
                  </Routes>
              </BrowserRouter>
          </ErrorBoundary>
      </CrashCatchProvider>

  );
}
export default App;

You may have noticed under there is another component called . You need to create this component with the following in as a minimum. You can add extra handling if you wish to this component but the below is required to submit unhandled crash exceptions:

import * as React from "react";
import {CrashCatchContext} from 'crashcatchlib-reactjs';

class ErrorBoundary extends React.Component {

    constructor(props) {
        super(props);
        this.state = { hasError: false };
    }

    componentDidCatch(error: Error, errorInfo: React.ErrorInfo)
    {
        this.setState({hasError: true});
        const crash_catch = this.context;
        crash_catch.reportUnhandledException(error);
    }

    render() {
        return this.props.children
    }
}
export default ErrorBoundary

This is the minimum you need to send error reports, these will send unhandled errors that occur within your project. You can however, send errors from components that are handled by a try/catch error.

For example, you can do the following in a functional component.

import * as React from 'react'

import * as React from 'react';
import {CrashCatchContext} from 'crashcatchlib-reactjs';

export default function MyComponent() {

  const crash_catch = useContext(CrashCatchContext);

  //If your project is typescript then you would need to do the following:
  //const crash_catch : CrashCatchContext = useContext(CrashCatchContext);

  const sendHandledCrash = () => {
    try
    {
      //Do something that would trigger an error
    }
    catch (err)
    {
      //The second parameter should be Low, Medium or High
      crash_catch.reportCrash(err, "Low");
    
      //You can also pass a third parameter which is JSON object of some extra debug information such as:
      crash_catch.reportCrash(err, "Low", {
        "method": "sendHandledCrash",
        "url": window.location.href
      });
    }
  }
  
  return (
    <button onClick={() => sendHandledCrash()}>Test</button>
  )
}