Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda