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

84
Views
¿Cómo puedo abrir el modal cuando hago clic en el botón Eliminar?

Estoy tratando de abrir un modal (que dice si está seguro de que desea eliminar el cliente) cuando un usuario hace clic en el botón para eliminar el cliente. Para abrir el modal, he creado una función openModal , pero no estoy seguro de cómo llamar a esta función, en este código.

ClientList.js

 export default function ListClients() { const [showModal, setShowModal] = useState(); const [userlist, setUserlist] = useState([]); const [selectedID,setSelectedID]=useState(''); function deleteClient() { if(selectedID){ const userParams = { clientName: clientName, country: country, clientid: selectedID, }; axios .delete(process.env + "client", { data: clientParams, }) .then((response) => { setClientlist(clientlist.filter((client) => client.id !== clientId)); }) .catch((error) => { console.log(error); }); } } return( <div> <tbody> {userlist.length > 0 ? ( userlist.map((userlist) => ( <tr key={userlist.id}> <td> <div"> {userlist.id} </div> </td> <td> <button type="button" onClick={() => setSelectedID(userlist.id)}> Delete </button> </td </tr> </tbody> //the idea is to pass the state for modal to show <ModalDelete showModal={showModal} setShowModal={setShowModal} onCancel={()=>setSelectedID('')} onDel={deleteClient}/> </div> );

ModalDelete.js

 export default function ModalDelete({ showModal, setShowModal,onCancel,onDel }) { return( <div> { showModal ? <Transition.Root show={showModal}> <div> <p> Are you sure you want to delete the client?</p> </div> <div> <button type="button" onClick={onDel}>Yes</button> <button type="button" onClick={() => { setShowModal(false); onCancel(); }} > Go Back </button> </div> </Transition.Root> : null } </div> ); }

¿Cómo puedo llamar a la función en este código para abrir el modal cuando se hace clic en el botón eliminado?

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

0

Simplemente podría hacer esto en el botón Eliminar (no necesitaría ese openModal ):

 <button type="button" onClick={() => { setSelectedID(userlist.id); setShowModal(true); }} > Delete </button>
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!