react-error-isolation
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

react-error-isolation (WIP)

NPM version NPM downloads NPM license Codecov Travis Bundle size

About

Don't let one error destroy the whole project

Similar Projects / Alternatives / Idea

How to Install

First, install the library in your project by npm:

$ npm install react-error-isolation

Or Yarn:

$ yarn add react-error-isolation

Getting Started

With Context configuration

• Import context provider and HOC in React application file:

import {
  ErrorIsolationProvider,
  withErrorIsolation,
} from 'react-error-isolation';

• Set ErrorIsolationProvider (if you want to use the same error screen for all components wrapped in withErrorIsolation HOC):

// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { ErrorIsolationProvider } from 'react-error-isolation';

import App from './App';

const ErrorScreen = () => {
  return (
    <div>
      <h1>Oops!</h1>
      <h2>Something went wrong.</h2>
    </div>
  );
};

ReactDOM.render(
  <ErrorIsolationProvider errorScreen={<ErrorScreen />}>
    <App />
  </ErrorIsolationProvider>,
  document.getElementById('root')
);

• Then use withErrorIsolation:

// App.js

import React from 'react';
import { withSuspense } from 'react-suspenser';

const App = () => {
  return (
    <div>
      <p>Hello World!</p>
    </div>
  );
};

export default withErrorIsolation()(App);

License

This project is licensed under the MIT License © 2020-present Jakub Biesiada

Dependencies (0)

    Dev Dependencies (27)

    Package Sidebar

    Install

    npm i react-error-isolation

    Weekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    38.7 kB

    Total Files

    14

    Last publish

    Collaborators

    • jbiesiada