samedi 22 octobre 2016

What is the recommended way to re-use methods inside ES6 React Components?

The React team advises against using mixins. Their suggestion for utility methods is to put them into a module and import them. I would be happy to do this, but their example doesn't show to do that when you need this.

Thus, I find myself constantly copying this method,

updateState = updates => {
    this.setState(state => update(state, updates));
};

And a few others into all my components. Is there a better, non-deprecated way to re-use "methods"?

By "method" I mean a non-static function utilizing this.

Aucun commentaire:

Enregistrer un commentaire