Cannot read property 'prepareStyles' of undefined

前端 未结 2 1690
北海茫月
北海茫月 2021-01-12 11:28

I am trying to open a Dialog box by a button click. When I am clicking the button the Dialog first of all is not opened and I am getting Error :

2条回答
  •  無奈伤痛
    2021-01-12 11:54

    All the material-ui component must be rendered inside tag, so we need to wrap topmost component (or at least any parent component) in material-ui's MuiThemeProvider component.


    Issue is, your Dialog is outside of the MuiThemeProvider tag, put dialog also inside it, it should work.

    Write it like this:

        
    } /> Dialog Text

    Suggestion:

    If you are using material ui elements in many components, then no need to put MuiThemeProvider tag on each page instead of that you can put in you homepage or better to put in index.js page, where we used to define all the routes, like this:

    const muiThemebtn = getMuiTheme()   
    
    ReactDOM.render((
      
          
              
                
              
          
      
    ), document.getElementById('app'));
    

提交回复
热议问题