-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6 classes and the use of mixins #659
Comments
+1 |
Of course :) Though, Sebastian just said at ReactConf "keep using mixins until there is a better solution". We haven't explored any alternatives to mixins, so we'll keep using them until then, but like React, we don't want to prescribe an object model either. |
I think it could keep existing anyway. The way I would use would be something like this: *Obs: Borrowed State Mixin the example from docs. import mixin from './utils';
import React from 'react';
import Router from 'react-router';
const {State, Link} = Router;
export default class Tab extends mixin(React.Component, State) {
render() {
let isActive = this.isActive(this.props.to, this.props.params, this.props.query);
let className = isActive ? 'active' : '';
let link = (
<Link {...this.props} />
);
return <li className={className}>{link}</li>;
}
} |
@edygar can you share the code in your mixin() function? |
fwiw, here is a simplistic implementation of Mixin that works similar to what edygar posted above:
You pass in regular javascript objects and it will treat the property Of course, this implementation does not include all of that React magic that merges lifecycle methods. In most cases I think we should avoid using mixins with lifecycle methods. That said, I still use |
@ryanflorence so how to handle this with ES6 Class after react-router 1.0? or should I just write a decorator to do the mixin functions with Babel? |
With React v0.13 the use of ES6 classes will be available. According to facebook/react#1380 mixins will not be magically supported for ES6 classes like they are today with
createClass
. With React Router v0.9 taking away the RouteStore methods and making them only available via mixins, are there any plans for supporting React Router with ES6 classes once v0.13 lands?The text was updated successfully, but these errors were encountered: