useFeedback

useFeedback(options: UseFeedbackOptions): UseFeedbackResult

The useFeedback() hook makes it easy to attach feedback to a message.

Basic example

1import { useFeedback } from '@markprompt/react';
2
3function FeedbackButton({ messageId }: { messageId: string }) {
4  const { submitFeedback, abort } = useFeedback({
5    projectKey: 'YOUR-PROJECT-KEY',
6  });
7
8  return (
9    <button onClick={() => submitFeedback({ vote: 1 }, messageId)}>
10      Upvote
11    </button>
12  );
13}

Hook API

UseFeedbackOptions

PropTypeDescription
feedbackOptionsOmit<SubmitFeedbackOptions, 'signal'>Enable and configure feedback functionality
projectKeystringMarkprompt project key
apiUrlstringThe base API URL

UseFeedbackResult

PropTypeDescription
abort() => voidAbort any pending feedback submission
submitFeedback(feedback: PromptFeedback, promptId?: string) => voidSubmit feedback for the current message
submitThreadCSAT(threadId: string, csat: CSAT) => voidSubmit CSAT for a thread