3 ms·
Can you outline the biggest problems with React's mixins? I haven't heard this complaint before.
by spicyj 10y ago
Can you outline the biggest problems with React's mixins? I haven't heard this complaint before.
- bcherny 10y agoI'm sure you and @danabromov have more thoughts on this, but I would generally constrain the mixin system more: - Don't let mixins call setState() directly; otherwise, it can be hard to track down what mutated the state. Have a well defined, canonical way to update state (proxy methods on the main component? Flux-style actions?) - Don't let mixins define a render() method; this is the component's responsibility - Separate mixin state from component state; mixins should not be able to see each others' state, and the component should not be able to see its mixins' state. Have a special API for a mixin to get its component's state (eg. this.getComponentState()) - Use vanilla ES6 mixins (class C extends mixin(A, B)) for interoperability with other libraries Again, Spessore is a great exploration of how to implement these sorts of constraints.