Is it possible to create a toast based on a url query param? #1633
Unanswered
gmcamposano
asked this question in
Q&A
Replies: 1 comment
-
Yes. See this example: "use client"
import { Button } from "@/registry/default/ui/button"
import { ToastAction } from "@/registry/default/ui/toast"
import { useToast } from "@/registry/default/ui/use-toast"
import { useEffect } from "react"
import { useSearchParams } from 'next/navigation'
export default function ToastDemo() {
const { toast } = useToast()
const searchParams = useSearchParams()
useEffect(() => {
if (searchParams?.get("a") === "b"){
toast({
title: "Scheduled: Catch up ",
description: "Friday, February 10, 2023 at 5:57 PM",
action: (
<ToastAction altText="Goto schedule to undo">Undo</ToastAction>
),
})
}
}, [toast, searchParams])
return (
<Button
variant="outline"
onClick={() => {
}}
>
Add to calendar
</Button>
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using nextjs, so my code looks like this:
Beta Was this translation helpful? Give feedback.
All reactions