An open API service indexing awesome lists of open source software.

https://github.com/tonysantana1492/sonner-ssr

An opinionated toast component for Next based on sonner
https://github.com/tonysantana1492/sonner-ssr

message next notifications react server-components snackbar ssr toast

Last synced: 6 months ago
JSON representation

An opinionated toast component for Next based on sonner

Awesome Lists containing this project

README

          

Sonner-SSR is a specialized toast component designed for Next.js applications, inspired by the [Sonner](https://sonner.emilkowal.ski/) library. It offers a streamlined and opinionated approach to displaying toast notifications within the Next.js framework.

## Features

- Seamless integration with Next.js
- Customizable themes
- Easy-to-use API
- Lightweight and performant

## Installation

To start using the library, install it in your project:

```bash
npm install sonner-ssr
```

## Usage

Create a `` component.

```jsx
"use client";

import { useTheme } from "next-themes";
import { Toaster } from "sonner-ssr";

type ToasterProps = React.ComponentProps;

const ToasterProvider = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme();

return (

);
};

export { ToasterProvider };
```

Add `` to your app. It will be the place where all your toasts will be rendered. After that, you can use `toast()` from anywhere in your app.

```jsx
'use server';

import type { PropsWithChildren } from 'react';
import { ToasterProvider } from 'sonner-ssr';

export default function RootLayout({ children }: PropsWithChildren) {
return (


{children}



);
}
```

## Example

Here's an example of how to trigger a toast notification:

```jsx
import { toast } from 'sonner-ssr';

function notify() {
toast('This is a toast notification!');
}
```

## Documentation

Find the full API reference in the [documentation](https://sonner.emilkowal.ski/getting-started).