javivelasco / react-css-themr

Easy theming and composition for CSS Modules.
MIT License
591 stars 68 forks source link

Uncaught TypeError: this.props.mapThemrProps is not a function #61

Closed alexeyMohnatkin closed 7 years ago

raveclassic commented 7 years ago

@alexeyMohnatkin Could you please provide a minimal representation gist/repo? I cannot reproduce the error.

javivelasco commented 7 years ago

That's weird. All test are passing and there is a default value set up, it shouldn't fail unless you give an option that is not a function there. @alexeyMohnatkin please give us an example! :)

alexeyMohnatkin commented 7 years ago

I need time to make example. I didin't pass any new options. I've just updated react-css-themr and got this error.

alexeyMohnatkin commented 7 years ago

It happens when I define defaultProps for decorated component. https://www.webpackbin.com/bins/-Kk0TTaHGCq00TebCuG1

raveclassic commented 7 years ago

@alexeyMohnatkin This happens because you overwrite statics after decorating the class. Just add them as static properties:

@themr(Symbol())
class Foo {
  static defaultProps = {};
  static propTypes = {};
}

Or extend them instead of overwriting:

Foo.defaultProps = {
  custom: 123,
  ...Foo.defaultProps
};
alexeyMohnatkin commented 7 years ago

I've already found solution, thank you

huchenme commented 6 years ago

I think the error message is not helpful. I have accidentally put defaultProps for one of the components using react-css-themr and got this error message "Uncaught TypeError: this.props.mapThemrProps is not a function" where no one has any clue where to find the root cause.

The expected behavior will be no runtime error if someone overrides the defaultProps in another component.

idangozlan commented 5 years ago

@alexeyMohnatkin what is the solution that you found?

alexeyMohnatkin commented 5 years ago

@idangozlan it's described here https://github.com/javivelasco/react-css-themr/issues/61#issuecomment-301258266