Is there a way to store the functions of a react class in a separate file then import those functions for use? The reason for wanting to do this would be purely to cut down on the size of my component and to group functions by category.
For instance:
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;
}
I know i can do this with helper functions that arent part of the component class. But I'd like to do it with my component functions to save space, and clean up my code.
this
in a way that won't produce bugs. for example an external arrow function will have a differentthis
context than theclass
. have you tried it an came across some issues? – Striped