New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rinshad-react-guard

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rinshad-react-guard

A robust React error boundary solution developed by [rinshad.com](https://rinshad.com) to elegantly handle runtime errors in React applications. Instead of showing the dreaded white screen of death, this library captures errors and displays a user-friendl

  • 1.0.10
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

rinshad-react-guard

A robust React error boundary solution developed by rinshad.com to elegantly handle runtime errors in React applications. Instead of showing the dreaded white screen of death, this library captures errors and displays a user-friendly error page while storing error details in session storage.

Features

  • 🛡️ Prevents white screen crashes in React applications
  • 🎯 Custom error page with clean UI
  • 💾 Stores error messages in session storage
  • 🔍 Configurable error filtering
  • ⚡ Compatible with Vite and React (jsx/tsx)
  • 🔄 Handles both sync and async errors
  • 🎨 Customizable styling

Installation

npm install rinshad-react-guard

or

yarn add rinshad-react-guard

Demo

Error Boundary Demo

Try it live: Demo Project

Usage

Basic Setup

Wrap your app's root component with the ErrorBoundary component:

import ErrorBoundary from 'rinshad-react-guard';

function App() {
  return (
    <ErrorBoundary>
      <YourApp />
    </ErrorBoundary>
  );
}

Advanced Usage with Excluded Keywords

You can exclude certain errors from being caught by providing keywords:

import ErrorBoundary from 'rinshad-react-guard';

function App() {
  const excludedKeywords = ['ChunkLoadError', 'NetworkError'];
  
  return (
    <ErrorBoundary excludedKeywords={excludedKeywords}>
      <YourApp />
    </ErrorBoundary>
  );
}

Accessing Error Messages

Error messages are automatically stored in session storage with the key rinshadReactGuardAlert. You can access them programmatically:

const errorMessage = sessionStorage.getItem('rinshadReactGuardAlert');

API Reference

ErrorBoundary Props

PropTypeDefaultDescription
childrenReactNoderequiredThe components to be wrapped by the error boundary
excludedKeywordsstring[][]Array of keywords to exclude from error catching

How It Works

  1. The ErrorBoundary component wraps your application and listens for any JavaScript errors
  2. When an error occurs:
    • The error message is captured and stored in session storage
    • The user is shown a friendly error page instead of a white screen
    • The error details are logged to the console for debugging
  3. Users can return to the home page using the provided button
  4. Browser back button navigation is handled to prevent users from seeing the error state again

Best Practices

  1. Place the ErrorBoundary at the root level of your application
  2. Use multiple ErrorBoundary components for different sections if needed
  3. Configure excluded keywords based on your application's needs
  4. Implement proper error logging and monitoring

Example

// main.jsx or App.jsx
import React from 'react';
import ErrorBoundary from 'rinshad-react-guard';
import YourApp from './YourApp';

function App() {
  const excludedKeywords = ['ChunkLoadError'];

  return (
    <ErrorBoundary excludedKeywords={excludedKeywords}>
      <YourApp />
    </ErrorBoundary>
  );
}

export default App;

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

License

MIT License

Support

For support, email rinshadcm34@gmail.com


Made with ❤️ by rinshad.com

Keywords

FAQs

Package last updated on 26 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc