Skip to content

Conversation

@alamenai
Copy link
Contributor

@alamenai alamenai commented Dec 18, 2025

What

Currently, the useConversation hook implements its callback logic inline, which makes the function difficult to predict, test, and maintain.

To improve clarity and testability, I extracted the inline callbacks into separate named handlers:

•	handleConnect
•	handleDisconnect
•	handleMessage
•	handleError

Additionally, I replaced React.useCallback with a direct useCallback import for consistency, and noted that our imports sometimes mix named and namespace styles.

Why

With the previous inline implementation, it was not possible to mock or spy on the useConversation logic effectively.

Extracting named handlers brings several benefits:

  1. Testability – Each handler can be individually mocked or spied on with Vitest, allowing focused unit tests without triggering the full conversation hook.

  2. Readability – The useConversation configuration is now a clean object with references to named handlers instead of nested inline functions, making it easier to scan and understand at a glance.

  3. Debuggability – Stack traces now show meaningful function names (e.g., handleError, handleDisconnect) instead of anonymous functions, making it easier to track and resolve issues.

@vercel
Copy link
Contributor

vercel bot commented Dec 18, 2025

@alamenai is attempting to deploy a commit to the ElevenLabs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant