1.0.14 • Published 8 months ago

@forbespro/lead-agent-hook v1.0.14

Weekly downloads
-
License
SEE LICENSE IN ./...
Repository
github
Last release
8 months ago

Lead Agent Hook

The useLeadAgent hook provides state management for the Lead Agent chat widget. It allows controlling the chat widget from anywhere in your application.

Installation

npm install @forbespro/lead-agent-hook

Usage

Provider Setup

Place the provider at the root of your application:

import { LeadAgentProvider } from '@forbespro/lead-agent-hook';

function App() {
  return (
    <LeadAgentProvider>
      <YourComponent />
      {/* All components using the hook must be inside this provider */}
    </LeadAgentProvider>
  );
}

Using the Hook

// In your component
import { useLeadAgent } from '@forbespro/lead-agent-hook';
import { LeadAgent } from '@forbespro/lead-agent';

function YourComponent() {
  const { isOpen, openChat, closeChat, toggleChat } = useLeadAgent();
  
  return (
    <>
      <button onClick={toggleChat}>Toggle Chat</button>
      
      {/* The LeadAgent component uses the same context */}
      <LeadAgent 
        initialMessages={[]} 
        initialChatId="123"
      />
    </>
  );
}

API

PropertyTypeDescription
isOpenbooleanCurrent open state of the chat widget
openChat() => voidFunction to open the chat widget
closeChat() => voidFunction to close the chat widget
toggleChat() => voidFunction to toggle the chat widget state

Troubleshooting

If the widget only opens but doesn't close:

  1. Ensure you have only ONE LeadAgentProvider at the app root
  2. Make sure all components using the hook are rendered inside this provider
  3. Check that your close button is using closeChat from the hook
  4. Verify you're not overriding the state with props
1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago