componentWillMount显示错误的状态值

时间:2015-12-26 06:06:42

标签: ruby-on-rails reactjs firebase

我正在测试带有反应和导轨的firebase的基本功能4.我跟随他们的basic tutorial并且我已经安装了firebase并通过npm反应火焰。

我的问题在于componentWillMount()。它显示不正确的状态。它显示了其他组件的状态。我可以通过网址推送到我的firebase数据库,但是收回信息是不正确的。登录我的firebase帐户,我看到了正确的信息。

Dashboard.jsx:

var React = require('react');
var Firebase = require('firebase');
var ReactFireMixin = require('reactfire');
var ref = new Firebase(<URL>/bids/); // I repeat this so makes sense to be global :)

var Dashboard = React.createClass({
 mixins: [ReactFireMixin],

 getInitialState: function() {
      return{
        filteredData: this.props.data, // this is from another component withing the same .jsx file. Maybe issue here?
        bids: []
      }
    },

    componentWillMount: function() {
      this.bindAsArray(ref, "bids");
    },

  textOneHandle (e) {
      this.setState({
        text1: e.target.value
      });
    },

  firebaseSubmit: function(e) {
      e.preventDefault();
      ref.push({
        text1: "a"
      });
    },

  render: function(){

  return(
  <div>
    <form>
      <input value={this.state.text1} onChange={this.textOneHandle}/>
      <button onClick={this.firebaseSubmit}>Push</button>
    </form>
  </div>
  );
  },

});

var Data = React.createClass({
  // has no getInitialState
  ...
});

module.exports = Dashboard; // main component

componentWillMount()mixins: [ReactFireMixin]移动到Data组件,我得到了正确的值,因为它没有初始状态函数,但我在Dashboard中需要它。我错过了一步吗?

0 个答案:

没有答案