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

210
Views
Select the text from one textarea and show the same but capitilized text in other textarea in react js

I have this simple react js application in which I am simply converting the text from upper to lower text using useState. But this text is being capitalized in the same textarea, I want to show the capitalized text on another textarea. and leave the lower case text in the same area. Here is my code:

import React from 'react'
import { useState } from 'react'

function TextArea(props) {

    const handleUpperClick= () => {
        let newText = text.toUpperCase();
        setText(newText)
    }

    const handleOnChange= (event) => {
        setText(event.target.value);
        console.log(event.target.value);
    }


    const [text, setText] = useState("Enter the text here please!");

  return (
      <div>
        <h1>{props.heading}</h1>
        <div className="mb-3">
            <label htmlFor="myBox" className="form-label">Example Text Area</label>
            <textarea name="" id="myBox" value={text} onChange={handleOnChange} cols="30" rows="10" className="form-control"></textarea>
        </div>
        <button className="btn btn-primary" onClick={handleUpperClick}>
            Convert to Upper Case
        </button>
        <div className="mb-3">
            <label htmlFor="myBox" className="form-label">Capital</label>
            <textarea name="" id="myBox" cols="30" rows="10" className="form-control"></textarea>
        </div>
        
      </div>
  )
}

export default TextArea

Please help me with this approach.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use useRef here as:

CODESANDBOX LINK

<textarea
    name=''
    id='myBox'
    cols='30'
    rows='10'
    ref={capitalCaseTextArea}
    className='form-control'
></textarea>;

and declare capitalCaseTextArea as:

const capitalCaseTextArea = useRef(null);

and on clicking button you can set value of textarea as:

const handleUpperClick = () => {
    let newText = text.toUpperCase();
    // setText(newText);
    capitalCaseTextArea.current.value = newText;
};
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!