ReactJs "Invariant violation..."经典 react 问题

标签 reactjs

这是一个典型的 react 问题,但我有点不知道如何处理它。 我只想动态渲染我的表格线,但我收到错误:” “未捕获错误:不变违规:processUpdates():无法找到元素的子元素 2。这可能意味着 DOM 意外变异(例如,由浏览器),通常是由于在使用表、嵌套标签(例如 ,

或 ,或在父级中使用非 SVG 元素。尝试使用 React ID .2.1.0 检查该元素的子节点。"

我知道 React 没有找到正确的 DOM 内容,但是如何处理呢?提前致谢!

<div className="panel-body" style={panelstyle}>
              <Table striped bordered condensed hover>
                <thread>
                  <th> Currency </th>
                  <th> Amount </th>
                  <th> Issuer </th>
                  <th> Limit </th>
                  <th> Limit Peer </th>
                  <th> No-Ripple </th>
                </thread>
                <tbody>
                  {this.state.ripplelines[this.address] ?

                              this.state.ripplelines[this.address].lines.map(function(line,i) {

                            return      (<tr>
                                          <td> USD </td>
                                          <td> 1500 </td>
                                          <td> raazdazdizrjazirazrkaẑrkazrâkrp </td>
                                          <td> 1000000000 </td>
                                          <td> 0 </td>
                                          <td> True </td>
                                        </tr>)       
                            ;
                        })             
                  : ""}
                </tbody>
              </Table>
            </div>

最佳答案

这里有一个答案:React js: Invariant Violation: processUpdates() when rendering a table with a different number of child rows

只需在渲染之前准备好行即可!

render:
 var rows = [];
      if(this.state.ripplelines[this.address] ) {
        _.each(this.state.ripplelines[this.address].lines, function(line) {
           rows.push(                   <tr>
                                          <td> somestuff!</td>

                                        </tr>)
        }); 
      }
return (
    <Table striped bordered condensed hover>
                    <thead>
                      <th> Currency </th>
                      <th> Amount </th>
                      <th> Issuer </th>
                      <th> Limit </th>
                      <th> Limit Peer </th>
                      <th> No-Ripple </th>
                    </thead>     
                    <tbody>
                      {rows}    
                    </tbody>
              </Table>
)

关于ReactJs "Invariant violation..."经典 react 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29123560/

相关文章:

reactjs - 如何从表单字段字符串设置枚举值?

reactjs - 在 React 构建中减少 Lighthouse "First Meaningful Paint"

reactjs - React.js 错误 : The service worker navigation preload request was cancelled before 'preloadResponse' settled

javascript - 我应该使用带有 Three.js 或 vanilla-js 的 UI 框架来创建动态 UI 吗?

javascript - react-dates 组件不允许选择当前日期之前的日期

javascript - 像面向对象编程一样将组件作为实例进行 react

javascript - 使用 React-Router 关闭 Bootstrap 模式后重定向

reactjs - React-router-redux 和 redux-immutable : You cannot change <Router history>; it will be ignored

javascript - react-query:仅在状态变量更改时重新获取查询

javascript - "onDrag"事件未在 react.js 中触发