use ref instead of identifier + document.getElementById()
See original GitHub issueI’m using your library for inspiration for a project where I have to wrap a vanillaJS wrapper of vis. So thank you!
In the process of doing that, I discovered that there is a more idiomatic way to get the underlying HTML node to pass to vis. You are using getElementById here: https://github.com/crubier/react-graph-vis/blob/master/src/index.js#L86
Instead, you can create a ref in your constructor:
this.container = React.createRef();
Attach it to your <div> in the render() method: <div ref={this.container} />
Then grab the reference to it here: https://github.com/crubier/react-graph-vis/blob/master/src/index.js#L109
this.container.current
In particular, this helps when running tests with Enzyme. I’m not sure where else it might help. If you want a PR, let me know, but those are the basic changes, I think.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
Yes this is now fixed, thanks!
True, this is old code that needs to be updated. I will try to have a look when I have more time, but if anyone wants to create a PR, feel free to do so, it’s just a few lines of code 😃