[英]Reference to parent html element in React child component
A simple Editor.jsx
component render method that renders a SVG element and a child component called <SystemBox />
一个简单的
Editor.jsx
组件render方法,该方法呈现SVG元素和名为<SystemBox />
的子组件
render() {
return (
<svg id="editor">
<SystemBox />
</svg>
);
}
In SystemBox.jsx
I need access to the actuall SVG html element to for example get to the getScreenCTM()
method on the SVG element. 在
SystemBox.jsx
我需要访问实际的SVG html元素,例如,获取SVG元素上的getScreenCTM()
方法。
How do I pass a reference to the SVG element in the parent to the child component? 如何将对父组件中SVG元素的引用传递给子组件?
I guess I could use document.getElementById('editor')
in the SystemBox.jsx
child component, but that doesn't right. 我想我可以在
SystemBox.jsx
子组件中使用document.getElementById('editor')
,但这是不对的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.