ui: Toast is not showing
When i use the default code for showing a toast it does not show on the page. Did I miss something or do I need to add some extra logic for toasts to show.
I added the following code to my client component:
<Button
variant='outline'
onClick={() => {
toast({
title: 'Uh oh! Something went wrong.',
description: 'There was a problem with your request.',
});
}}>
Show Toast
</Button>
Im working on a nextjs project with ts. not sure if you need more information.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19
@Default-01 Did you put the Toaster component in the layout.tsx?
Your layout.tsx should have a Toaster like this as mentioned in the docs. Hope that solves it
@Default-01 You can add
'use client'in the toaster.jsx|tsx file at ‘@/components/ui/toaster’. That way you don’t need to add'use client'in your layout file. Should fix this issue.Yes, the
useToast()andtoast({})must be in a client component, but the Toaster should be in thelayout.tsx, like the example below:You are an Angel!