有没有办法将react类的函数存储在一个单独的文件中,然后导入这些函数以供使用?想要这样做的原因纯粹是为了减少组件的大小并按类别对功能进行分组.
例如:
import functionIWantToImport from '../functions/functionIWantToImport';
import anotherFunction from '../functions/anotherFunction';
Class Test extends React.Component {
constructor(props){
super(props);
this.state = {};
}
//and then include the functions like below:
functionIWantToImport;
anotherFunction;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用不属于组件类的辅助函数来完成此操作.但我想用我的组件功能来节省空间,并清理我的代码.