Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
How to translate a text using button in react app?

I am new to react, I am building a text utility app in it user can able to do some stuff in his text like change to uppercase, lowercase, translate etc. I am currently stuck on how to translate text using a button. I search a lot but not able to find any effective solution.

Here is my TextForm Component:

import counterpart from 'counterpart';
import Translate from 'react-translate-component';

counterpart.registerTranslations('hn',{
    textarea:{text}
});

counterpart.setLocale('en');


export default function TextForm(props) {
    const [text, setText] = useState('');
    const handleOnChange = (event) => {
        setText(event.target.value);
    }
    const handleUpChange = () => {
        let newText = text.toUpperCase();
        setText(newText);
    }
    const handleLoChange = () => {
        let newText = text.toLowerCase();
        setText(newText);
    }
    const handleTrChange = () => {
        <Translate content='textarea' component='textarea' />
        let newText = text
        setText(newText);

    }
    return (
        <>
            <div className="container my-3">
                <h1>{props.heading}</h1>
                <div className="mb-3">
                    <textarea className="form-control" id="myBox" value={text} onChange={handleOnChange} placeholder="Enter here" rows="8"></textarea>
                </div>
                <button className="btn btn-primary mx-1" onClick={handleUpChange}>Convert to Uppercase</button>
                <button className="btn btn-primary mx-1" onClick={handleLoChange}>Convert to Lowercase</button>
                <button className="btn btn-primary mx-1" onClick={handleTrChange}>Translate into Hindi</button>
            </div>
            <div className="container my-3">
                <h2>Your Text Summary</h2>
                <p>{text.split(' ').length} words and {text.length} characters</p>
                <p>{0.008 * text.split(' ').length} Minutes read</p>
                <h3>Preview</h3>
                <p>{text}</p>
            </div>
        </>
    )
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create a custom Button Component where you just hand over callback in this component. Button Component has to have useEffect hook where you call its callback with some params and conditions and then you should set state in any place what you want(usually it's local useState hook).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!