Install Hot Toast
command line
npm i react-hot-toast
Check out the official docs.
Declare the Toaster
pages/_app.js
import Navbar from '../components/Navbar';
import { Toaster } from 'react-hot-toast';
function MyApp({ Component, pageProps }) {
return (
<>
<Navbar />
<Component {...pageProps} />
<Toaster />
</>
);
}
Trigger a Toast Message
pages/index.js
import toast from 'react-hot-toast';
export default function Home() {
return (
<div>
<button onClick={() => toast.success('hello toast!')}>
Toast Me
</button>
</div>
);
}