Skip to content

nishathub/react-custom-alert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”” react-custom-toast-simple

A simple and reusable React toast (alert) component with context β€” customizable, lightweight, and easy to use in any React project.


✨ Features

  • βœ… Custom alert messages like toasts
  • βœ… Easy setup using React Context
  • βœ… Works across the whole project
  • βœ… Auto dismiss after timeout
  • βœ… Customizable look and duration

πŸ“¦ Installation

npm install react-custom-toast-simple

πŸš€ Usage

    1. Wrap Your App in ToastProvider
// App.jsx or root layout
import { ToastProvider } from 'react-custom-toast-simple';

function App() {
  return (
    <ToastProvider>
      <YourApp />
    </ToastProvider>
  );
}
    1. Place the Toast Component Once (e.g., in Layout)
import { BToast } from 'react-custom-toast-simple';

const Layout = () => {
  return (
    <>
      <Navbar />
      <BToast /> {/* Toast pop-up component */}
      <Outlet />
      <Footer />
    </>
  );
};
    1. Use the customAlert() Function Anywhere
import { useCustomAlert } from 'react-custom-toast-simple';

const MyComponent = () => {
  const customAlert = useCustomAlert();

  const handleClick = () => {
    customAlert('This is a custom toast!', 2000); // optional second arg = duration (ms)
  };

  return <button onClick={handleClick}>Show Toast</button>;
};

🎨 Customization

You can customize the look of the toast by editing the toast component styles:

<div className="bg-red-900 text-white w-72 p-4 text-center rounded-lg">
  <p>{toastText}</p>
</div>

🧩 Example

customAlert("Saved successfully!", 1500);
  • First parameter: Message to display
  • Second parameter: Duration in milliseconds (optional, default: 1500ms)

🀝 License

  • MIT β€” Free to use, modify, and share.

πŸ’‘ Author

Ashraf Nishat
GitHub Profile

About

A lightweight and customizable React toast library with context support for global alerts and auto-dismiss notifications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published