react-error-isolation

Don't let one error destroy the whole project

Usage no npm install needed!

<script type="module">
  import reactErrorIsolation from 'https://cdn.skypack.dev/react-error-isolation';
</script>

README

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