Skip to content

@vowel.to/client v0.3.3-beta


@vowel.to/client / react / useSyncContext

Function: useSyncContext()

ts
function useSyncContext(context): void;

Defined in: lib/vowel/hooks/useSyncContext.ts:70

Hook that automatically syncs context to the Vowel client

Updates the Vowel client's context whenever the provided context value changes. The context is automatically sent to the AI via session.update if a session is active.

Parameters

ParameterTypeDescription
contextRecord<string, unknown> | nullContext object to sync with Vowel client. Use null to clear context. Changes are detected via deep comparison of JSON.stringify result.

Returns

void

Example

tsx
function MyComponent() {
  const [user, setUser] = useState(null);
  
  // Automatically sync user context
  useSyncContext(user ? { userId: user.id, userName: user.name } : null);
  
  return <div>Hello {user?.name}</div>;
}