Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 567 Bytes

useError.md

File metadata and controls

34 lines (24 loc) · 567 Bytes

useError

React side-effect hook that returns an error dispatcher.

Usage

import { useError } from 'use-reacts-hooks';

const Demo = () => {
  const dispatchError = useError();

  const clickHandler = () => {
    dispatchError(new Error('Some error!'));
  };

  return <button onClick={clickHandler}>Click me to throw</button>;
};

// In parent app
const App = () => (
  <ErrorBoundary>
    <Demo />
  </ErrorBoundary>
);

Reference

const dispatchError = useError();
  • dispatchError — Callback of type (err: Error) => void