1.0.0 • Published 4 years ago

@matthamlin/use-error v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

@matthamlin/use-error

A hook to trigger error boundaries higher up in the React tree.

API

import { useError } from '@matthamlin/use-error'

function ComponentThatThrows() {
  let trigger = useError()

  useEffect(() => {
    if (thing) {
      // Calling trigger will force the parent error boundary
      trigger(`Passed 'thing' to ComponentThatThrows`)
    }
  })

  return <SomeComponent />
}

useError can be called with a single argument that is either:

  • A string, this string will be passed to the Error constructor directly or
  • Any other type which will be thrown