Hacker News new | ask | show | jobs
by Lazare 3993 days ago
Mmm, not sure I see a huge difference between:

    import Foo from './foo';
    let Bar == React.createClass({});
    Bar = Foo(Bar);
    Bar.mixinFunction();
and:

    import Foo from './foo';
    let Bar == React.crateClass({mixins: Foo});
    Bar.mixinFunction();
In both cases I'm adding functions to my Bar component; in neither case is it defined in my file or added directly.

It is true that in the general case the mixin approach would mutate the internal state of Bar, whereas the higher-order component approach would re-render Bar with updated props, which is a solid win for the latter style. (Conversely, a mixin can check the state of the underlying component, while a higher-order component cannot, which means that you can't really implement shouldComponentUpdate as a higher-order component.)

But it's really a fairly subtle difference, and I wouldn't say that either is particularly more transparent. :)