Amidii Amidii - 21 days ago 6
React JSX Question

ReactJS Reflux using mixins with ES6

How do you solve mixins with reflux using ES6?

Like this:

mixins: [Reflux.listenTo(myStore, "onChange")]
^


Results in error "Unexpected token" with arrow shown above.

React v 0.14.7
Reflux v 0.4.0

Answer

Theoretically mixins works for react 0.14 .

They don't work if you use ES6 syntax (especially classes). In ES6 we use high order components instead.

You can't simply replace reflux mixins by some ES6 syntax. You have to find not mixins solution for reflux. There is interesting thread about it :

https://github.com/reflux/refluxjs/issues/225

And there are some links which may help you:

https://www.npmjs.com/package/reflux-provides-store https://www.npmjs.com/package/reflux-state-mixin

Or you can try create high order component from mixins by this component:

https://github.com/timbur/react-mixin-decorator