Siddu hadapad
Siddu hadapad

Reputation: 3713

reactjs componentWillMount not calling every time when i open modal

i am displaying table data inside modal dialog, when i click table row to edit data it will open another modal dialog, here i am getting row data by using clicked row id inside componentWillMount(). but when i close edit modal dialog and try to edit other table row componentWillMount() will not called. so edit modal dialog is empty. why componentWillMount not calling every time?

Upvotes: 1

Views: 931

Answers (2)

Siddu hadapad
Siddu hadapad

Reputation: 3713

I used following steps to fix it.

  1. i used {(this.state.open) ? <Dialog open={true} ></Dialog> : null
  2. second step by unmounting the component componentWillUnmount() { }

Upvotes: 1

Vlad Povalii
Vlad Povalii

Reputation: 1640

As Nir H already mentioned, Dialog component mounts into the dom only once, and then after you close it, becomes invisible (by changing the left position to -10000px) but still present inside the DOM.

So its clearly that componentWillMount and componentDidMount methods will be called only once. If you want to open Dialog component with different options every time, you can do the folloving:

  1. Save ref to the Dialog component instanse in the parent component:

ref={instance => {this.RowDialog = instance}}

  1. Then you can open Dialog by using it handleOpen method:

onRowClick = (event) => { this.RowDialog.handleOpen(); }

Upvotes: 1

Related Questions