material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

ES6 Mixins and how to use?

Open kkotwal94 opened this issue 10 years ago • 6 comments

How would we add a decorator for something like:

let {StylePropable, StyleResizable} = Mixins;

I've been trying to imitate the FullWidthSection.jsx in the docs, but using Mixins in ES6 have always been weird to me I know we need some kind of decorator correct? Would it be something like this?

@(StylePropable, StyleResizable)
React.Component {
....
}

But im sure i need to call some kind of method outside of it, I don't know what though.

I've came to this btw trying to use functions like .mergeAndPrefix and this.isDeviceSize.

kkotwal94 avatar Dec 27 '15 09:12 kkotwal94

I went ahead and installed core-decorators, and then did something like this:

import {ClearFix, Mixins, Styles} from 'material-ui';
let {StylePropable, StyleResizable} = Mixins;
let DesktopGutter = Styles.Spacing.desktopGutter;
import {mixin} from 'core-decorators';


@mixin(StylePropable, StyleResizable)

It says Cannot read property 'deviceSize' of null, even though it is filled as such


this.isDeviceSize(StyleResizable.statics.Sizes.SMALL) && styles.rootWhenSmall,
          this.isDeviceSize(StyleResizable.statics.Sizes.LARGE) && styles.rootWhenLarge)}>

However functions from StyleProbable work pretty good!

kkotwal94 avatar Dec 27 '15 09:12 kkotwal94

@kkotwal94 My advice is to not use those mixins. The React team is not going to support mixins with components based on ES6/2015 classes. We have started and are continuing to move towards replacing those mixins with other approaches like utility functions, higher order components, or inheritance.

More importantly, if it's not explicitly documented on the material-ui website (such as StylePropable), it's best to not use it since it could be changed or even removed at any time.

Does that make sense?

newoga avatar Dec 30 '15 06:12 newoga

Yea, it does. I just found it helpful that those kind of mixins already existed and I knew what they did, using them was just a problem. But thanks for clearing that up makes complete sense!

kkotwal94 avatar Dec 30 '15 08:12 kkotwal94

Please ask further questions on stackoverflow. thank you ^_^

alitaheri avatar Dec 30 '15 20:12 alitaheri

@alitaheri Any chance you'll add any mixins documentation? I have no idea how to use them.

kpennell avatar Oct 25 '18 18:10 kpennell

👋 Thanks for using MUI Core!

We use GitHub issues exclusively as a bug and feature requests tracker, however, this issue appears to be a support request.

For support, please check out https://mui.com/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others. If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

github-actions[bot] avatar Dec 21 '22 08:12 github-actions[bot]