feedbackWidget.tsx 850 B

12345678910111213141516171819202122232425262728
  1. import {useEffect} from 'react';
  2. import {BrowserClient, getCurrentHub} from '@sentry/react';
  3. import {Feedback} from '@sentry-internal/feedback';
  4. import ConfigStore from 'sentry/stores/configStore';
  5. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  6. /**
  7. * Use this to display the Feedback widget in certain routes/components
  8. */
  9. export default function FeedbackWidget() {
  10. const config = useLegacyStore(ConfigStore);
  11. const widgetTheme = config.theme === 'dark' ? 'dark' : 'light';
  12. useEffect(() => {
  13. const hub = getCurrentHub();
  14. const client = hub && hub.getClient<BrowserClient>();
  15. const feedback = client?.getIntegration(Feedback);
  16. const widget = feedback?.createWidget({
  17. colorScheme: widgetTheme,
  18. });
  19. return () => {
  20. feedback?.removeWidget(widget);
  21. };
  22. }, [widgetTheme]);
  23. return null;
  24. }