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

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

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 Denunciar

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 Denunciar

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 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