Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda