首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Row Row的Row.render错误

使用Row Row的Row.render错误
EN

Stack Overflow用户
提问于 2016-07-18 12:54:29
回答 1查看 174关注 0票数 0

我使用react-bootstrap作为它的布局特性。我正在使用Row标记并获得以下错误:

不变冲突: Row.render():必须返回有效的ReactComponent。您可能已返回未定义的数组或其他无效对象。

我的用法如下。请告诉我任何我可能错过的东西:

代码语言:javascript
复制
var Row = require('react-bootstrap/lib').Row;


module.exports = React.createClass({

validateForm: function() {
        console.log("i am validating the transaction details");
        var input=this.refs.form;
        return(input.validateForm());

    },
render : function(){
return(
<div>
<Row>
</Row>
  </div>
); 

}

});

编辑:

即使以下情况也会产生相同的错误:

代码语言:javascript
复制
var React = require('react');
var ReactBootstrap = require('react-bootstrap');


module.exports = React.createClass({

validateForm: function() {
        console.log("i am validating the transaction details");
        var input=this.refs.form;
        return(input.validateForm());

    },
render : function(){
return(
<div>
<ReactBootstrap.Row>Hello World
</ReactBootstrap.Row>
  </div>
); 

}

});

编辑:在执行console.log(Reactbootstrap.Row)时,我得到以下输出:

代码语言:javascript
复制
function (props, context, updater) {
          // This constructor gets overridden by mocks. The argument is used
          // by mocks to assert on what gets mounted.

          if (process.env.NODE_ENV !== 'production') {
            process.env.NODE_ENV !== 'production' ? warning(this instanceof Constructor, 'Something is calling a React component directly. Use a factory or ' + 'JSX instead. ) : void 0;
          }

          // Wire up auto-binding
          if (this.__reactAutoBindPairs.length) {
            bindAutoBindMethods(this);
          }

          this.props = props;
          this.context = context;
          this.refs = emptyObject;
          this.updater = updater || ReactNoopUpdateQueue;

          this.state = null;

          // ReactClasses doesn't have constructors. Instead, they use the
          // getInitialState and componentWillMount methods for initialization.

          var initialState = this.getInitialState ? this.getInitialState() : null;
          if (process.env.NODE_ENV !== 'production') {
            // We allow auto-mocks to proceed as if they're returning null.
            if (initialState === undefined && this.getInitialState._isMockFunction) {
              // This is probably bad practice. Consider warning here and
              // deprecating this convenience.
              initialState = null;
            }
          }
          !(typeof initialState === 'object' && !Array.isArray(initialState)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getInitialState(): must return an object or null', Constructor.displayName || 'ReactCompositeComponent') : _prodInvariant('82', Constructor.displayName || 'ReactCompositeComponent') : void 0;

          this.state = initialState;
        }

上面的组件名为TransactionDetails,我在transaction.jsx中使用了这个TransactionDetails组件,如下所示:

代码语言:javascript
复制
'use strict';

var Layout = require('../layout.jsx');
var React = require('react');
var Validation = require('react-validation');
var validator = require('validator');
var TextInput=require('../common/textInput.jsx');
var RadioButtonSet=require('../common/radioButtonSet.jsx');
var TransactionDetails = require('./transactionDetails.jsx');
var AddressList = require ('../suspects/AddressList.jsx');
module.exports = React.createClass({
 onClick:function(){
   console.log("I was called from transactions");
 }, 
 validateForm: function(e) {

        console.log("i am validating the form");
        var input=this.refs.transactionDetails;
        if(input.validateForm()===false){
          e.preventDefault();
          alert("There are validation errors");
        }


    },

  render: function render() {
      var populatedTransaction;
      var transactions = this.props.transactions;
      var suspects= this.props.suspects;
      var populatedSuspect = suspects[0];
      for(var i=0 ;i<transactions.length;i++){
        if(transactions[i].id===this.props.params.Id){
            populatedTransaction = transactions[i];
            break;
        }
      }
    return (
        <Layout {...this.props} addBundle='true'>
        <section className="suspects-section">
        <h2>Transactions</h2>
        <div>
        <form method="post" action="/PostTransaction" onSubmit={this.validateForm}>
        <input type="hidden" name="transaction_id" value={populatedTransaction.id} />
        <TransactionDetails ref="transactionDetails" populatedTransaction={populatedTransaction} {...this.props} />
        <input ref="numberInput" type="hidden" name="_csrf" value={this.props._csrf} />
        <input type="submit" value="Save"  />
        </form>
        </div>
        </section>
        </Layout>
    );
  }
});
EN

回答 1

Stack Overflow用户

发布于 2016-07-18 13:24:19

我们尝试导入ReactBootstrap作为var ReactBoostrap = require('react-bootstrap'),并使用您的行组件作为<ReactBootstrap.Row>。它起作用了。

代码语言:javascript
复制
module.exports = React.createClass({

validateForm: function() {
        console.log("i am validating the transaction details");
        var input=this.refs.form;
        return(input.validateForm());

    },
render : function(){
return(
<ReactBootstrap.Row>Hello World
</ReactBootstrap.Row>
); 

}

});

JSFIDDLE

然而,

代码语言:javascript
复制
var ReactBoostrap = require('react-bootstrap')
var Row = ReactBootstrap.Row

应该能正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38437260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档