Q:

File seperation in Three.js using React Classes

I've built a three.js application, but i'm struggling to figure out how i can put my functions in seperate files. 
I got this mesh function that i would like to be in its own seperate file. 
My functions
componentDidMount() {
    this.sceneSetup();
    this.addCustomSceneObjects();
    this.startAnimationLoop();
    window.addEventListener("resize", this.handleWindowResize);
  }

My Scene Function
  sceneSetup = () => {
    const width = this.el.clientWidth;
    const height = this.el.clientHeight;

    this.scene = new THREE.Scene();
    this.camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
    this.camera.position.z = 5;
    this.controls = new OrbitControls(this.camera, this.el);
    this.renderer = new THREE.WebGLRenderer();
    this.renderer.setSize(width, height);
    this.el.appendChild(this.renderer.domElement); // mount using React ref
  };

My Mesh Function This is the function i'd like to have in a separate file. 
  addCustomSceneObjects = () => {
    const geometry = new THREE.BoxGeometry(2, 2, 2);
    const material = new THREE.MeshPhongMaterial({color: 0x156289, emissive: 0x072534, side: THREE.DoubleSide, flatShading: true});
    this.cube = new THREE.Mesh(geometry, material);
    this.scene.add(this.cube);
  }

Any suggestions on how i can do this would be very much appreciated. 

A:

I have never used three.js but your requirement is not a framework specific. 
// addCustomSceneObjects.js
export default ({ scene, cube}) => {
    const geometry = new THREE.BoxGeometry(2, 2, 2);
    const material = new THREE.MeshPhongMaterial({color: 0x156289, emissive: 
    0x072534, side: THREE.DoubleSide, flatShading: true});
    cube = new THREE.Mesh(geometry, material);
    scene.add(this.cube);
  }

And then, use the extracted function like this
    // index.jsx

    import addCustomSceneObjects from './addCustomSceneObjects'

    componentDidMount() {
        //...
        addCustomSceneObjects({ scene: this.scene, cube: this.cube }) 

    }

