-
-
Save Ebrahim-Ramadan/67b80aa96bcaf29be6907baf0b4d24bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use client"; | |
import { useAuth } from "@clerk/nextjs"; | |
import * as Sentry from "@sentry/nextjs"; | |
import { useEffect, useState } from "react"; | |
function createWidget() { | |
return Sentry.getFeedback()?.createWidget(); | |
} | |
function useFeedbackWidget(shouldMount: boolean) { | |
const [widget, setWidget] = useState<ReturnType<typeof createWidget> | null>( | |
null, | |
); | |
useEffect(() => { | |
// Mount if true and no widget exists | |
if (shouldMount && !widget) { | |
const newWidget = createWidget(); | |
setWidget(newWidget); | |
} | |
// Unmount if false and widget exists | |
if (!shouldMount && widget) { | |
widget.removeFromDom(); | |
setWidget(null); | |
} | |
}, [shouldMount, widget]); | |
} | |
export default function SentryFeedbackWidget() { | |
const auth = useAuth(); | |
useFeedbackWidget(!!auth?.isSignedIn); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment