reactjs - React / D3 错误“未捕获的 TypeError:无法读取属性 'ownerDocument' of null”
问题描述
我正在尝试使用d3
但在反应的上下文中将一些数据绑定到 dom 元素。我找不到 d3 代码的任何问题,所以我想知道我是否错误地处理了 React 生命周期/引用。
import React from "react";
import { select, selectAll } from "d3-selection";
class Test extends React.Component {
componentDidMount() {
this.makeD3();
}
makeD3 = () => {
console.log("maked3");
selectAll(this.refs.node).data([1, 2, 3, 4]);
select(this.refs.node).data([1, 2, 3, 4]); // try just select?
};
render() {
return (
<div ref="node">test</div>
);
}
}
解决方案
推荐阅读
- php - 如何在 Symfony 4 中将上下文传递给自定义事件订阅者?
- python - ValueError:检查输入时出错:预期 lstm_6_input 具有形状 (87482, 1) 但得到的数组具有形状 (87482, 3)
- java - 将 List 转入 Java Stream,然后删除 List 的一个元素。出现一些错误
- eclipse - 将火花作业从本地提交到位于eclipse中服务器上的火花集群时访问错误
- java - 在 Java 中,如何在 TextArea 中使用多线程?我需要同步我的线程吗?
- android-studio - Android 应用程序的电池耗尽问题
- binary - Python 将 1 0 字符串写入/读取到二进制文件
- php - Flysystem如何获取WEBDAV目录下的文件列表?
- python - 读取具有两个外键列的表数据
- swift - 如何从 AVCapturePhotoOutput 中获取图像 url?