useBhaShaIME Hook
The `useBhaShaIME` hook provides the most flexible way to integrate transliteration into your React components. It gives you complete control over the UI while handling all the transliteration logic.
Basic Usage
import { useBhaShaIME } from '@bhashaime/core';
function MyComponent() {
const { input, output, setInput } = useBhaShaIME({
language: 'gujarati',
autoTransliterate: true,
});
return (
<div>
<input
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Type in English..."
/>
<div>Transliterated: {output}</div>
</div>
);
}
Live Demo:
Advanced Usage
The hook offers several options to customize its behavior and provides a rich set of return values for building complex interfaces.
Hook Options
language
The initial language for transliteration. Can be changed later using `setLanguage`.
autoTransliterate
Whether to automatically transliterate input as the user types. When false, use the `transliterate` method manually.
onTransliterationChange
Callback function called whenever the input or output changes. Useful for side effects like logging or analytics.
Return Values
input: string
The current input text.
output: string
The transliterated output.
language: SupportedLanguage
The current language.
setInput: (text: string) => void
Function to programmatically set the input text.
setLanguage: (lang: SupportedLanguage) => void
Function to change the transliteration language.
transliterate: (text: string) => string
Function to manually trigger transliteration for a given text. Respects the currently set language.
clear: () => void
Clears both the input and output fields.