HomeServicesOfAmerica / styled-material-components

Styled Components implementation of Material Design
Other
71 stars 51 forks source link

Cannot read 'property' of undefined #272

Closed tastycode closed 6 years ago

tastycode commented 6 years ago

Using latest stable create-react-app, and latest version of styled-material-components. I get the following error when trying to import and use <Button primary>test</Button>. I am importing styled-material-components using import { Button } from "styled-material-components"

image

petegivens commented 6 years ago

hi @tastycode, you'll need to wrap your app in the ThemeProvider.

import { Button, ThemeProvider } from 'styled-material-components';

...
export default () => (
  <ThemeProvider>
    <Button primary>test</Button>
  </ThemeProvider>
);

This will use the default Material Design light theme, but if you want to override any properties you can pass in your own theme object. The default theme will overwrite any properties you provide:

<ThemeProvider theme={{ primary: '#ff0000', accent: '#2cd6d6' }}>
  <Button primary>test</Button>
</ThemeProvider>

Additionally, you can wrap other smaller components or sections of your app with a nested theme provider to overwrite theme properties just in that component/section.