简体   繁体   中英

React throwing an error saying that setTimeout is not a function?

Im trying to use the XTK library in react and keeps telling me that the setTimeout function is not a function. My code seems to be pretty clean and it functions well if I just use it directly with the html. However Im trying to get it to work in a react component and it just fails straight up. Can anyone tell me what Im doing wrong or where I can look to fix this?

error message

code for the component:

import React from 'react';


import window from 'xtk';
// window.X is now available

export default class VtkGeometryRenderer extends React.Component {
  constructor (){
    super();
  }
  shouldComponentUpdate(){
    return false;
  }
  componentDidMount(){
    // create a new 3d renderer
    var r = new  window.X.renderer3D();
    //r.container = 'r';
    r.init();

    // create a mesh from a .vtk file
    var skull = new window.X.mesh();
    skull.file = 'http://x.babymri.org/?avf.vtk';

    // add the object
    r.add(skull);

    // .. and render it
    r.render();

  }
  render() {

    return (
          <div
              ref={(c) => {
              this.rootContainer = c;
            }}
          />
        );
};

Oh the npm package just adds X on the window namespace.

Change:

import window from 'xtk'

to:

import 'xtk'

This will add X to the existing window object, instead of reassigning it like you are doing with that import statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM