javascript - 使用语义 UI React(表、粘性、可见性组件)的无限滚动表导致 `<tr> cannot appear as a child of <div>` 警告

标签 javascript reactjs semantic-ui-react

我使用 Semantic UI React 创建了一个无限滚动的表格。我正在使用 StickyTableVisibility 组件的组合。它似乎表现正确并完成了我想要的。

但是我收到以下警告:

Warning: validateDOMNesting(...): <div> cannot appear as a child of <thead>.
Warning: validateDOMNesting(...): <tr> cannot appear as a child of <div>. 

我可以安全地忽略这些警告吗?一切似乎都很好,我只是担心以后会出现更大的问题。

我正试图找到一种更好的方法来实现无限滚动,而不会出现上面列出的警告。这是当前的实现:

import React from 'react'
import PropTypes from 'prop-types'
import { Sticky, Table, Visibility } from 'semantic-ui-react'


class InfiniteScrollTable extends React.Component {
  constructor(props) {
    super(props)

    this.state = {}
  }

  handleContextRef = contextRef => this.setState({ contextRef })

  render() {
    const { contextRef } = this.state
    const { children, headerRow, ...rest } = this.props

    return (
      <div ref={this.handleContextRef}>
        <Table {...rest}>

          <Table.Header>
            <Sticky context={contextRef}>{headerRow}</Sticky>
          </Table.Header>

          <Visibility
            as="tbody"
            continuous={false}
            once={false}
            onBottomVisible={() => console.log('This will call API')}
          >
            {children}
          </Visibility>

        </Table>
      </div>
    )
  }
}


InfiniteScrollTable.propTypes = {
  headerRow: PropTypes.element.isRequired,
  children: PropTypes.arrayOf(PropTypes.element).isRequired,
}

InfiniteScrollTable.defaultProps = {}

export default InfiniteScrollTable

最佳答案

这里的问题是 React 警告你你没有正确嵌套你的变量。虽然它在您正在测试的浏览器上运行良好,但在实现 DOM 的其他浏览器上可能会出现问题。

我建议您通过移动 Sticky 来更正此问题。到表的顶部并通过 <Visibility as={Table.Body}...<Visibility as="tbody"... .不确定这些是否可行,但如果我要使用类似的框架,我会这样解决它。

关于javascript - 使用语义 UI React(表、粘性、可见性组件)的无限滚动表导致 `<tr> cannot appear as a child of <div>` 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47761148/

相关文章:

reactjs - 当包裹在 <Provider> 中时,React Native Context 呈现空白屏幕

semantic-ui - 如何设置语义 UI 下拉大小以匹配按钮等

reactjs - 如何在 Semantic-UI-React 中将 Modal 居中?

html - 如何为单页 React 应用程序中的链接实现 "Open link in new tab"

java - 如何将这些正则表达式组合到 JavaScript 中

javascript - 比较来自 PostgreSQL 的 javascript 日期时间和时间戳

javascript - 在 JS 中将月份名称转换为月份编号的最简单方法? (一月 = 01)

javascript - 哪些脚本加载器(AMD 或非 AMD)与 Backbone.js/Underscore 一起使用?

reactjs - 使用 redux-form 6.0.0-rc.3 时, Action 创建者未显示在 "this.props"中

reactjs - 如何使用 Gatsby 以编程方式在 React Helm 中显示图像?