1
votes

In material UI docs, the implementation of Dialog box is with the help of onClick of a Button. But can the Dialog box can be appear using the if-else condition in the render method of the component? Like in a login form, if the credentials are correct then go the next component, and if not then a pop up Dialog box should appear using the if-else condition on the props that i get from the redux store.

Thanks for the help in advance.

2

2 Answers

0
votes

You need call button click event into your if-else condition.

I created app on stackblitz Click here

here you can check in demo.js how I set value and opened the dialog using if-else condition.

0
votes

The visibility of the dialog box is controlled by a state value. So where ever or when ever you set that state value to true, or, from the below code of Prasad Phule,

   <Dialog
      open={this.state.open}
      onClose={this.handleClose}
      aria-labelledby="alert-dialog-title"
      aria-describedby="alert-dialog-description"
    >

when ever the state value this.state.open which is provided to the open props of <Dialog>, the dialog box will be shown no matter if its an onClick function or an if condition.