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

144
Views
How to change css property with function in react

I want to change visiblty properties with a function. I want when user click on the button change visible properties on textarea. How can ı make ? enter image description here

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

0

const [show, setShow] = useState(false)

const changeVisibility = () => {
  setShow(!show)
}

return (
<>
    <div className="ui form">
        {show && (
            <div className="field">
                <textarea rows="2"></textarea>
            </div>
        )}
    </div>
    <button onClick={changeVisibility}>show</button>
</>  
);
about 4 years ago · Juan Pablo Isaza Report

0

Here's a simple example.

  1. Use useState to manage the visibility of the text area.

  2. Attach a handler to the button that calls a function that updates the state.

  3. Use a class called hidden. Initially the textarea won't have it but you can conditionally add it if the updated state tells you to.

const { useEffect, useState } = React;

function Example() {

  const [ visible, setVisible ] = useState(true);

  function handleClick() {
    setVisible(!visible);
  }

  return (
    <div>
      <button onClick={handleClick}>Toggle visibilty</button>
      <textarea className={!visible && 'hidden'}></textarea>
    </div>
  );
};

ReactDOM.render(
  <Example />,
  document.getElementById('react')
);
.hidden { visibility: hidden; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
<div id="react"></div>

about 4 years ago · Juan Pablo Isaza Report

0

Make a state variable to keep track of the textarea visible state, then in the textarea tag, add style for using that state variable. Then onlick event, toggle the state variable either to false or true.

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!