如何解决使用反应窗口渲染表行
我正在使用react-window
和react-table 7
(以及主要的UI表)创建虚拟表。
我要嵌入FixedSizeList而不是TableBody。像这样:
<TableBody {...getTableBodyProps()}>
<FixedSizeList
height={listHeight}
itemCount={rows.length}
itemSize={rowHeight}
>
{RenderRow}
</FixedSizeList>)
</TableBody>
和RenderRow返回TableRows。像这样:
const RenderRow = React.useCallback( ({ index,style }) =>
{
const row = rows[index];
prepareRow(row);
const rowProps = row.getRowProps();
return (<TableRow
{...row.getRowProps({
style,})} />);
}
由于react-window
的工作方式,它创建了两个div
来实现列表滚动,并根据需要动态嵌入所需的TableRows,从而导致输出react js警告。
webpack-internal:///490:506 Warning: validateDOMnesting(...): <tr> cannot appear as a child of <div>
我只是不想忽略此警告,因为这可能会导致其他警告不被注意。 (我也不希望在测试时使用发布版本)
那么有可能防止该警告发出吗?
还是可以对表行使用react-window
,而不会收到此警告?
更新:
尝试将innerElementType
设置为tbody
的建议。
这将更改FixedSizeList
呈现的内部div。
来自:
<div style="position: relative; height: 96px; overflow: auto; will-change: transform; direction: ltr;">
<div style="height: 96px; width: 100%;">
到
<div style="position: relative; height: 96px; overflow: auto; will-change: transform; direction: ltr;">
<tbody style="height: 96px; width: 100%;">
因此,它们现在包含在tbody中。
所以我想我还需要使用outerElementType
来更改外部div
,以处理div
警告中的table
,但我想不起来任何有效的方法都可以...
如果我不想包含thead
,可以将outerElementType
设置为table
,将innerElementType
设置为tbody
解决方法
FixedSizeList
接受innerElementType
prop,以便您指定要使用的HTML标记而不是div
。据我从阅读the code可以看出,它或多或少需要是一个标记字符串。
您可能希望将此innerElementType
设为tbody
,这意味着要稍微修改父元素。我猜想您不想继续使用TableBody
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。