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

143
Views
How can I assign modal form component opening function to any another button component

I have 2 components: ModalForm and BookCard. The ModalForm is supposed to be put inside of the BookCard. When you put the ModalForm - it creates new button and functionates as it has to. But what if instead of creating new button I want to assign ModalForm's functionality to already existing button?

BookCard.js

const BookCard = ({id, name, cover, description, price, count, loadResponse}) => {
    return (
        <Card>
            //some code
            <ModalForm /*some props*/ />
            <button className="edit-button"> // <- the button, I want to be assigned to be opening modal
                <box-icon name='edit-alt'/>
            </button>
        </Card>
    );
}

ModalForm.js

const ModalForm = ({/*some props*/}) => {
    //some code
    return (
        <div>
            <Button onClick={handleClickOpen} /> // <- the button that is being shown instead of the wanted one
            //some code    
        </div>   
    );
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Its looks like you need to handle the logic in the most up component in your case BookCard. So ModalForm has some props like isOpen in BookCard you need state like isModalOpened and then add callback onClick that change state (isModalOpened) and then react pass that prop(isOpen) to your ModalForm.

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!