Getting Started
API Reference

API Reference

This page documents the API for the prompt-my-client-react package.

usePrompt Hook

The usePrompt hook provides a flexible way to integrate AI text enhancement into your custom components.

Hook Return Values

PropertyTypeDescription
generatePrompt(text: string, prompt: string, tone?: string, style?: string) => Promise<void>Function to generate AI response
isLoadingbooleanLoading state indicator
errorstring | nullError message if any
resultstring | nullAI response result
reset() => voidFunction to reset all states

Hook Options

OptionTypeDescription
onSuccess(response: string) => voidCallback when AI response succeeds
onError(error: string) => voidCallback when an error occurs

Usage Example

import { usePrompt } from 'prompt-my-client-react';
 
function MyComponent() {
  const { generatePrompt, isLoading, error, result } = usePrompt({
    onSuccess: (response) => {
      setText(response);
      console.log('AI Response:', response);
    },
    onError: (error) => {
      console.error('Error:', error);
    }
  });
 
  const handleGenerate = async () => {
    await generatePrompt(
      "Hello world",           // text
      "Make it formal",        // prompt
      "professional",          // tone
      "concise"               // style
    );
  };
 
  return (
    <div>
      <button onClick={handleGenerate} disabled={isLoading}>
        {isLoading ? 'Processing...' : 'Make Professional'}
      </button>
      {error && <p>Error: {error}</p>}
      {result && <p>Result: {result}</p>}
    </div>
  );
}

AIDropDown Component

The main component that provides an AI-powered dropdown interface for text enhancement.

Props

Required Props

PropTypeDescription
textstringThe text content to be processed by AI
aiResponseCallback(response: string) => voidCallback function to handle AI responses

Optional Props

PropTypeDefaultDescription
sizestring'48px'Size of the AI button
renderIcon() => React.ReactNodeundefinedCustom icon renderer function
iconColorstringundefinedColor of the default icon
promptOptionsPromptOption[]Built-in optionsCustom prompt options
dropdownStyleReact.CSSPropertiesDefault stylesCustom dropdown styling
optionStyleReact.CSSPropertiesDefault stylesCustom option styling
optionHoverStyleReact.CSSPropertiesDefault stylesCustom hover styling
buttonStyleReact.CSSPropertiesDefault stylesCustom button styling

Types

PromptOption

type PromptOption = {
  prompt: string;      // The actual prompt sent to AI
  label: string;       // Display label in dropdown
  tone?: string;       // Tone modifier (optional)
  style?: string;      // Style modifier (optional)
}

Usage Example

import { AIDropDown } from 'prompt-my-client-react';
 
function MyComponent() {
  const [text, setText] = useState('');
 
  const handleAIResponse = (response: string) => {
    if (response) {
      setText(response);
    }
  };
 
  return (
    <div>
      <textarea 
        value={text}
        onChange={(e) => setText(e.target.value)}
        placeholder="Type your text here..."
      />
      <AIDropDown 
        text={text} 
        aiResponseCallback={handleAIResponse}
        size="48px"
        iconColor="#007bff"
        renderIcon={() => <span>✨</span>}
      />
    </div>
  );
}

Default Prompt Options

The component comes with these pre-built prompt options:

LabelDescription
Fix GrammarCorrects grammatical errors
Professional ToneConverts text to professional language
Make it ShortCondenses text while maintaining meaning
Make it DetailedExpands text with more information
ConversationalMakes text more casual and friendly
CreativeAdds creative flair to the content
PersuasiveMakes text more convincing and compelling