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

140
Views
¿Cómo cambiar el estado de carga del botón solo si se hizo clic?

Tengo dos botones que usan la misma condición de carga, pero sigo haciendo clic en uno, el otro también cambia el estado a cargando. ¿Como puedo resolver esto?

 const { isLoading } = useRespondConsent(); <ButtonPrimary isLoading={isLoading} onClick={() => handleRespond(true)}> Send </ButtonPrimary> <Button isLoading={isLoading} onClick={() => handleRespond(false)}> Not send </Button>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. Identifique sus botones de alguna manera, con una identificación o un atributo de datos.

  2. Inicializa tu estado como un objeto.

  3. Dos funciones. El primero en manejar la actualización de estado cuando se hace clic en un botón. El segundo para determinar si un botón isLoading . En este ejemplo (por comodidad) si el botón está "cargando", se desactiva.

 const { useState } = React; function Example() { // Initialise state with an empty object const [ buttonState, setButtonState ] = useState({}); function handleButton(e) { // Grab the id from the button's dataset const { id } = e.target.dataset; // Preserve the existing state, and // update the value of the property identified // by the id setButtonState({ ...buttonState, [id]: !buttonState[id] }); } // Takes an ide and returns the value // of the property identified by the id, or false function isLoading(id) { return buttonState[id] || false; } return ( <div> <Button id="send" isLoading={isLoading('send')} handleButton={handleButton} >Send </Button> <Button id="notsend" isLoading={isLoading('notsend')} handleButton={handleButton} >Not send </Button> </div> ); }; function Button(props) { const { id, isLoading, handleButton, children } = props; // Disable the button if isLoading // is true return ( <button data-id={id} disabled={isLoading} onClick={handleButton} >{children} </button> ); } ReactDOM.render( <Example />, document.getElementById('react') );
 <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
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!