Rendering a polydata in a div + React
See original GitHub issueObjective: to display a polydata in a div using React
Method:
in App.js, I have:
class App extends React.Component {
constructor(props) {
super(props);
this.vtkRef = React.createRef();
}
componentDidMount() {
const container = this.vtkRef.current;
update(container);
}
render() {
return <div ref={this.vtkRef} style={{width: 500, height: 500}}/>;
}
}
The update(container) calls:
const update = (container) => {
// bunch of stuff happening
// ...
const openglRenderWindow = vtkOpenGLRenderWindow.newInstance();
renderWindow.addView(openglRenderWindow);
openglRenderWindow.setContainer(container);
const {width, height} = container.getBoundingClientRect();
openglRenderWindow.setSize(width, height);
const interactor = vtkRenderWindowInteractor.newInstance();
interactor.setView(openglRenderWindow);
interactor.bindEvents(container);
interactor.initialize();
interactor.setInteractorStyle(vtkInteractorStyleTrackballCamera.newInstance());
}
In addition, I followed the instruction in this thread to make sure the webpack.config.js is setup correctly. To be specific, I ran npm run eject, modified the webpack.config.js by following this instruction, remove the node modules directory followed by npm install and npm i worker-loader
Now I’m getting this error:

My guess is this has to do something with how I configured the webpack or passing the container as I tested the code without React and had no issues whatsoever.
Any comments is greatly appreciated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Rendering Elements - React
Rendering an Element into the DOM We call this a “root” DOM node because everything inside it will be managed by React DOM....
Read more >VTK.js, React, JavaScript: Load VTK files - Stack Overflow
I am using a node server. In addition I have written the code as React code: import React from 'react'; ...
Read more >Changing scalars to render via setActiveScalars - Web - VTK
Hello, I am attempting to change the scalars that are rendered in a vtk.js ... <div className="App"> <div id="renderBox"> {polydata && <div ......
Read more >Using vtk.js with React - Kitware, Inc.
This is a quickstart tutorial for using vtk.js with React. ... import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
Read more >Understanding How To Render Arrays in React | DigitalOcean
Rendering Adjacent Elements with React.fragment. Prior to React v16.2, you could wrap a block of components in a <div> element. This would lead ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For future reference, this project can be helpful to add the required loaders in the required order for create-react-app:
https://github.com/thewtex/craco-vtk
https://kitware.github.io/vtk-js/docs/intro_vtk_as_es6_dependency.html