我有一个非常烦人的问题,我需要有关我的组件的帮助。它在这样的上下文中使用:
<table>
<thead>/* ... */</thead>
<tbody>
<COMPONENT>
<ChildComponent>/* ... */</ChildComponent>
<ChildComponent>/* ... */</ChildComponent>
<ChildComponent>/* ... */</ChildComponent>
</COMPONENT>
</tbody>
</table>
ChildComponent是一个包含其他组件但最终呈现简单 HTML 的组件<tr>
在component.tsx 中,我需要为第 n 个孩子获取 DOM 值(offsetTop 和 clientHeight)。
我尝试了很多事情:
ReactDOM.findDOMNode(children[n])给我:
参数似乎不是 ReactComponent。键:$$typeof, type, key, ref, props, _owner, _store
children[n].ref只是给我空- 不能向孩子添加引用
- 这类作品:
children.map((child, index) =>
index === n ? (
<div style={{display: contents}} key={index} ref={ref}>
) : child
)
给我警告(但有效!):
index.js:2178 警告:validateDOMNesting(...): 不能作为 . 在 tr(由 FoldControlContainer 创建)...
有更好的解决方案吗?我尝试使用 <> 或其他“透明”的 DOM 组件而不是div,但它没有用。