-
Notifications
You must be signed in to change notification settings - Fork 47
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
getInitialState -> componentWillMount order is not preserved #8
Comments
Doing it in componentWillMount is necessary because getInitialState just doesn't exist, and we can't augment the constructor. I think the fix here is manually merging state in componentWillMount rather than using setState, and doing it before calling the actual componentWillMount functions. A PR would be very appreciated; it's going to be a little while before I have time to do this and fix up the tests. |
@endragor does 1.2.1 work for you? |
Right now - no, it doesn't, because of bug in React: facebook/react#1740 |
@endragor I think it's fixed. import React from 'react';
import reactMixin from 'react-mixin';
var Mixin = {
getInitialState(){
return {'foo': 'bar'};
},
componentWillMount(){
console.log(JSON.stringify(this.state, null, 4));
}
}
class C extends React.Component {
constructor(){
this.state = {'baz': 'quux'};
}
render(){
return <div />;
}
}
reactMixin.onClass(C, Mixin);
React.renderToString(<C />);
// stdout
{
"baz": "quux",
"foo": "bar"
} The only concern is how duplicate keys are handled, I don't think it's done correctly currently. |
@brigand thanks! |
react-mixin makes mixin's
getInitialState
wrapped intocomponentWillMount
and called after the mixin's originalcomponentWillMount
.Normally,
state
is initialized fromgetInitialState
beforecomponentWillMount
is called, and socomponentWillMount
is able to rely on the initialized state.As an example, this breaks Formsy.Mixin that uses
this.state
fromcomponentWillMount
.The text was updated successfully, but these errors were encountered: