sentry-docs icon indicating copy to clipboard operation
sentry-docs copied to clipboard

sentry/react feedback example for "Bring Your Own Button" doesn't compile

Open chdsbd opened this issue 1 year ago • 3 comments

Core or SDK?

Platform/SDK

Which part? Which one?

React User Feedback Configuration

Description

In this code example, @sentry/react doesn't export Feedback in the latest SDK.

import { BrowserClient, Feedback, getClient } from "@sentry/react";

function MyFeedbackButton() {
  const client = getClient<BrowserClient>();
  const feedback = client?.getIntegration(Feedback);

  // Don't render custom feedback button if Feedback integration isn't installed
  if (!feedback) {
    return null;
  }

  return (
    <button
      type="button"
      onClick={async () => {
        const form = await feedback.createForm();
        form.appendToDom();
        form.open();
      }}
    >
      Give me feedback
    </button>
  );
}

Suggested Solution

import { BrowserClient, feedbackIntegration, getClient } from "@sentry/react";

type FeedbackIntegration = ReturnType<typeof feedbackIntegration>

function MyFeedbackButton() {
  const client = getClient<BrowserClient>();
  const feedback = client?.getIntegrationByName<FeedbackIntegration>('Feedback');

  // Don't render custom feedback button if Feedback integration isn't installed
  if (!feedback) {
    return null;
  }

  return (
    <button
      type="button"
      onClick={async () => {
        const form = await feedback.createForm();
        form.appendToDom();
        form.open();
      }}
    >
      Give me feedback
    </button>
  );
}

chdsbd avatar Jun 08 '24 20:06 chdsbd

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] avatar Jun 08 '24 20:06 getsantry[bot]

That results in this, which seems a bit wrong? But yes the current example just doesn't work.

image

Stanzilla avatar Jun 09 '24 00:06 Stanzilla

Is there an update on this issue? I have had to use the workaround for custom UI as well.

SheetalParanjpeKodiak avatar Jun 24 '24 20:06 SheetalParanjpeKodiak

The docs for this have been updated in the meanwhile, so I am closing this issue - please re-open if you still encounter this somewhere!

mydea avatar Sep 05 '24 14:09 mydea