govind jha
govind jha

Reputation: 107

how get id of tr and use it in post api request body in reactjs

I am working with reactjs with axios. Currently, I am using get api to get a list. Each column has a unique id and I want to use this id for a new post API "post request" body. currently i am clicking on button and open a dialog. in dialog i submit a form and i want to use tr id in dialog form post body request. currently i m using static id but i want to use dynamic id from tr.

Button

<Button variant="outlined" color="primary" id={data.id} onClick={handleDialogOpenTwo}>
    Faq
  </Button>

Post api and want to use here

axios.post('https://test3.com/api/faqs',
  { 
    ipoId: '1511',   **i want to use this button id here**
    faqList:[
     { question: this.state.question, 
      answer: this.state.answer,
     }
    ]
  }
)

Dialog

  <Dialog open={isOpenTwo} onClose={handleDialogCloseTwo} className="quistion_Popup">
    {/* <DialogTitle>Confirm</DialogTitle> */}
    <DialogContent>
      <DialogContentText>Add Faq</DialogContentText>
      <FaqPage/>
    </DialogContent>

  </Dialog>

enter image description here

enter image description here

Upvotes: 1

Views: 490

Answers (1)

Hossein Azizdokht
Hossein Azizdokht

Reputation: 1015

In grid component Get button's id by e.target.id and set it in a state; then send this state as a props to Dialog components then use it.

<button id="test" onClick={(e) => setState(e.target.id)}>Test Button</button>

Upvotes: 1

Related Questions