React Usage

how to use it with React.js

First you need to Import the convertToAmharic function from the amharic-converter package.

import { convertToAmharic } from 'amharic-converter';

Then, we need to create a state variable called amharicText(or anything you want), using the useState hook, we need to initialize it with an empty string.handleInputChange function is responsible for updating the state variable whenever the input text changes. It extracts the English text from the events target value, passes it to the convertToAmharic function to obtain the corresponding Amharic text, and sets the amharicText state with the converted text.

// Create a state variable to hold the Amharic text
const [amharicText, setAmharicText] = useState('');

// Define an event handler to update the state when the input changes
const handleInputChange = (event) => {
    const englishText = event.target.value;
    const amharicResult = convertToAmharic(englishText, {
       includeNumbers: false, 
       enhance: false, 
});
// amharicResult.correctText to access the Corrected spelling 
// amharicResult.suggestions to access possibly the next words 
// amharicResult.convertedText to access the amharic text 
    setAmharicText(amharicResult.convertedText);
};

To integrate this functionality into your application, you can use the amharicText state variable to display the converted Amharic text within an input element. Here is an example of how you can achieve this in JSX.

<input
 type="text"
 value={amharicText}
 onChange={handleInputChange}
>

In the above code, the value attribute of the input element is bound to the amharicText state variable, ensuring that it reflects the current converted Amharic text. The onChange event is connected to the handleInputChange function, so any changes to the input will trigger the conversion and update the state accordingly.