0

I try to add material-ui to my React project.

after running npm install material-ui -S I try to include an example from the documentation.

      <div>
        <RaisedButton onClick={this.handleTouchTap} label="Click me" />

        <Popover
          open={open}
          anchorEl={anchorEl}
          anchorOrigin={{ horizontal: 'left', vertical: 'bottom' }}
          targetOrigin={{ horizontal: 'left', vertical: 'top' }}
          onRequestClose={this.handleRequestClose}
        >
          <Menu>
            <MenuItem primaryText="Refresh" />
            <MenuItem primaryText="Help &amp; feedback" />
            <MenuItem primaryText="Settings" />
            <MenuItem primaryText="Sign out" />
          </Menu>
        </Popover>
      </div>

I import desired material-ui component in the following way import { RaisedButton, Popover, Menu, MenuItem } from 'material-ui';

and this leads to an error with following stack trace.

enter image description here

1

2 Answers 2

1

Did you follow the usage in their docs?

You need to include a import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; at the top of your app.

Sign up to request clarification or add additional context in comments.

1 Comment

no, I did not. didn't know about that. need to try this out
1

I also have this same problem. I hope I can add to the answer submitted by BravoZulu.

You need to wrap your material-ui code source snippet with an element tag of <MuiThemeProvider> (like for example below):

<MuiThemeProvider>

    ...code source from material-ui 

</MuiThemeProvider>

Hope this helps someone else in the future. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.