How to use react-error-boundary - 5 common examples

To help you get started, we’ve selected a few react-error-boundary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joelshepherd / tabliss / src / containers / Plugin.tsx View on Github external
Component: React.ComponentType;
  data?: object;
};

const Plugin: React.FC = ({ id, Component, data }) => {
  // Plugin API this
  const api = useApi(id);
  const props: API = {
    ...api,
    data,
  };

  return ;
};

export default withErrorBoundary(Plugin, Crashed, captureException);

function useApi(id: string) {
  const dispatch = useDispatch();

  // Cache
  const cache = useSelector(state => state.cache[id]);
  const boundSetCache = React.useCallback(
    (cache: object) => dispatch(setCache(id, cache)),
    [dispatch, id],
  );

  // Data
  const boundSetData = React.useCallback(
    (data: object) => dispatch(setData(id, data)),
    [dispatch, id],
  );
github joelshepherd / tabliss / src / views / shared / Plugin.tsx View on Github external
import Crashed from './Crashed';
import { useApi } from '../../utils/useApi';

type Props = {
  id: string;
  Component: React.ComponentType>;
};

const Plugin: FC = ({ id, Component }) => {
  // Create plugin API
  const api = useApi(id);

  return ;
};

export default withErrorBoundary(Plugin, Crashed, captureException);
github universitas / universitas.no / webpack / src / universitas / components / PageSwitch / PageSwitch.js View on Github external
const pageWrapper = (Page, toTitle = R.F) => {
  const title = R.pipe(
    toTitle,
    R.unless(R.is(String), R.always('')),
    R.trim,
    capitalize,
  )
  const locationToProps = R.pipe(
    R.converge(R.merge, [R.prop('payload'), R.pick(['pathname'])]),
    R.converge(R.assoc('pageTitle'), [title, R.identity]),
  )
  return [withErrorBoundary(Page, undefined, onError), locationToProps]
}
github geosolutions-it / MapStore2 / web / client / components / app / StandardApp.jsx View on Github external
const {localConfigLoaded} = require('../../actions/localConfig');
const {loadPrintCapabilities} = require('../../actions/print');

const ConfigUtils = require('../../utils/ConfigUtils');
const LocaleUtils = require('../../utils/LocaleUtils');
const PluginsUtils = require('../../utils/PluginsUtils');

const assign = require('object-assign');
const url = require('url');
const {isObject, isArray} = require('lodash');

const urlQuery = url.parse(window.location.href, true).query;

require('./appPolyfill');

const ErrorBoundary = require('react-error-boundary').default;

/**
 * Standard MapStore2 application component
 *
 * @name  StandardApp
 * @memberof components.app
 * @prop {function} appStore store creator function
 * @prop {object} pluginsDef plugins definition object (e.g. as loaded from plugins.js)
 * @prop {object} storeOpts options for the store
 * @prop {array} initialActions list of actions to be dispatched on startup
 * @prop {function|object} appComponent root component for the application
 * @prop {bool} printingEnabled initializes printing environment based on mapfish-print
 * @prop {function} onStoreInit optional callback called just after store creation
 * @prop {function} onInit optional callback called before first rendering, can delay first rendering
 * to do custom initialization (e.g. force SSO login)
 * @prop {string} mode current application mode (e.g. desktop/mobile) drives plugins loaded from localConfig
github exercism / website / app / javascript / components / ErrorBoundary.tsx View on Github external
export const useErrorHandler = (
  error: unknown,
  { defaultError }: { defaultError: Error }
): void => {
  const handler = useReactErrorHandler()

  useEffect(() => {
    if (!error) {
      return
    }

    if (error instanceof Error) {
      Bugsnag.notify(error)

      handler(new HandledError(defaultError.message))
    } else if (error instanceof Response) {
      error
        .clone()
        .json()
        .then((res: { error: APIError }) => {
          handler(new HandledError(res.error.message))

react-error-boundary

Simple reusable React error boundary component

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis

Similar packages