How To Import Plain Javascript Helper Classes Into React?
I have a React class that I have written in ES6 style such as: export default class App extends React.Component { constructor(props) { super(props); let HClass
Solution 1:
Currently, new HelperClass()
is only available inside your constructor. You can use the some_function
there only.
Generally, you'll do:
For use inside specific method:
// outside the constructormyMethod() {
let HClass = newHelperClass();
HClass.some_function();
}
For use in any method:
// inside the constructorthis.props.HClass = new HelperClass();
// to callthis.props.HClass.some_function();
Or, simply using this:
// inside the constructorthis.HClass = newHelperClass();
// to callthis.HClass.some_function();
Post a Comment for "How To Import Plain Javascript Helper Classes Into React?"