useAlert

Hook for managing alert notifications and displaying messages to users.

Overview

The useAlert hook provides methods to show alerts with different types (success, error, info, warning) and manage their display.

Return Value

Terminal
interface UseAlertReturn {
  showAlert: (
    type: 'success' | 'error' | 'info' | 'warning',
    message: string,
    options?: {
      absolute?: boolean;
      position?: 'top' | 'bottom';
      duration?: number;
    }
  ) => void;
  alertProps: object;
}

Usage

UseAlertExample.tsx
import { useAlert, Alert } from 'hyperkit';

function App() {
  const { showAlert, alertProps } = useAlert();
  
  const handleSuccess = () => {
    showAlert('success', 'Transaction successful!', {
      absolute: true,
      position: 'top'
    });
  };
  
  return (
    <div>
      <button onClick={handleSuccess}>
        Show Alert
      </button>
      <Alert {...alertProps} />
    </div>
  );
}