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

projectKeystring

Markprompt project key

apiUrlstring

The base API URL

UseFeedbackResult

PropTypeDescription
abort() => void

Abort any pending feedback submission

submitFeedback(feedback: PromptFeedback, messageId?: string) => void

Submit feedback for the current message

submitThreadCSAT(threadId: string, csat: CSAT) => void

Submit CSAT for a thread

submitThreadCSATReason(threadId: string, reason: string) => void

Submit CSAT reason for a thread