Custom free error boundary component for React
npm install hadz-error-handler``markdown
hadz-error-handlerHadz Error Handler
is a custom error boundary component for React that helps you handle and display errors gracefully within your application.
hadz-error-handler
Installation
You can install using npm:
`
bash
`
npm install hadz-error-handler
ErrorBoundary
Usage
Wrap your application with the component to capture and handle errors. This component will display an error message when an error occurs within its children. You can also provide a custom error message to be displayed.
`
jsx
`
import React from 'react';
import ErrorBoundary from 'hadz-error-handler';
function App() {
return (
// Define the action to take on error, like reporting it
// to a server or displaying a user-friendly error message.
}
>
{/ Your application content /}
);
}
export default App;
action
Customization
You can customize the error handling behavior by providing an prop to the ErrorBoundary component, which specifies the action to be taken on an error. Modify the componentDidCatch method in the component to handle error reporting or logging.
`
jsx
`
// Define the action to take on error, like reporting it
// to a server or displaying a user-friendly error message.
}
>
{/ Your application content /}
customError
Custom Error Message
You can also provide a custom error message to be displayed when an error occurs by passing the prop:
`
jsx
`
// Define the action to take on error, like reporting it
// to a server or displaying a user-friendly error message.
}
customError={Error: Something went wrong.}
>
{/ Your application content /}
``
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Hadz
Contributing
Feel free to contribute by submitting issues and pull requests.
Acknowledgments
- Inspired by the need for a simple error boundary component.