Replies: 7 comments 5 replies
-
Well @imtheaman , you are right, we have two exports called
Sooner:To use sooner , you must import import { Toaster } from "@/components/ui/sonner"
import { toast } from "sonner"
toast("Event has been created.") ToasterTo use sooner , you must import import { Toaster } from "@/components/ui/toaster"
import { useToast } from "@/components/ui/use-toast"
toast({
title: "Scheduled: Catch up",
description: "Friday, February 10, 2023 at 5:57 PM",
}) Toaster and Sooner are not related to each other and you don't need to install toaster to use sooner or vice versa. In caseIn case, if you want to use both of the toaster and sooner, you can use namespace import to avoid the conflicst. import { toast } from './components/ui/use-toast'
import { toast as sonner } from 'sonner'
import { Button } from './components/ui/button'
import { Toaster as Sonner } from './components/ui/sonner'
import { Toaster } from './components/ui/toaster'
export default function ToastSimple() {
return (
<div className={`m-auto flex h-screen w-screen items-center justify-center gap-4`}>
<Button
onClick={() =>
toast({
title: 'This is a toast',
description: 'This is a toast description',
})
}
>
Toast
</Button>
<Button onClick={() => sonner('This is a sooner not a toast')}>Sonner</Button>
//include these in you root or wherever you want.
<Toaster />
<Sonner />
</div>
)
} probable-spoon-p4r4ggxg7rqc6rjr-5000.app.github.dev.-.Google.Chrome.2024-01-08.18-25-52.mp4In case, if you are not satisfied with the answer, you can comment down. |
Beta Was this translation helpful? Give feedback.
-
usecase of Sonner ain' clear yet |
Beta Was this translation helpful? Give feedback.
-
Yeah, I think both are kind of same, you can use one of them according to your preferences. 😉 |
Beta Was this translation helpful? Give feedback.
-
It's either or. You can pick between |
Beta Was this translation helpful? Give feedback.
-
I need a Toast component for my app. How do I choose between |
Beta Was this translation helpful? Give feedback.
-
Nope, they both display messages with actions and icons and colors, etc. It's all up to you! They both can display a title, description, and icon. Again, it's all up to you. The only visual difference is the design. Some people might prefer the design of Sonner over Toast and some other person might prefer the reverse. Hence, just go with whichever one you like best - especially if you're not bound by a design.
How do you choose? I'm not sure what you wish to get as a response to the question, but I reckon you can just install whichever one of them you prefer to use. I'd argue that's how to choose. |
Beta Was this translation helpful? Give feedback.
-
I think from the perspective of an FE developer, the fundamental difference is that you can use sonner outside a React component. If you adopt toaster, you have to call the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
i used Toaster exported by sonner.tsx and toast wasn't showing up, then i used toaster.tsx's export and it shows up. why do we have two exports of the same component?
Beta Was this translation helpful? Give feedback.
All reactions