Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs ES6 React组件内部重复使用方法的推荐方法是什么?_Reactjs_Design Patterns - Fatal编程技术网

Reactjs ES6 React组件内部重复使用方法的推荐方法是什么?

Reactjs ES6 React组件内部重复使用方法的推荐方法是什么?,reactjs,design-patterns,Reactjs,Design Patterns,反应小组。他们的任务是将它们放入一个模块并导入。我很乐意这样做,但是他们的例子没有说明当您需要此时如何这样做 因此,我发现自己一直在复制这种方法 updateState = updates => { this.setState(state => update(state, updates)); }; 还有一些其他的加入到我所有的组件中。有没有更好的、不被弃用的方法来重用“方法” “方法”是指利用ES7类属性的非静态函数 // updateState.js f

反应小组。他们的任务是将它们放入一个模块并导入。我很乐意这样做,但是他们的例子没有说明当您需要
时如何这样做

因此,我发现自己一直在复制这种方法

updateState = updates => {
    this.setState(state => update(state, updates));
};
还有一些其他的加入到我所有的组件中。有没有更好的、不被弃用的方法来重用“方法”


“方法”是指利用ES7类属性的非静态函数

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

    // App.js
    import updateState from './updateState.js'

    class App extends Compnent {
        updateState = updateState.bind(this);
    }