首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >componentDidMount没有更新我的状态吗?

componentDidMount没有更新我的状态吗?
EN

Stack Overflow用户
提问于 2016-08-31 01:29:49
回答 1查看 119关注 0票数 0

我是一个新的反应,我只是做了一个视图计数器的各种divs.For,我需要的高度的div和scrollTop的height.But后,我必须设置的值,它不工作的values.But。

代码语言:javascript
复制
var React = require('react');
var ReactDOM = require('react-dom');
var NewsDetail = require('./news-details');
var $ = require('jquery');
module.exports = React.createClass({
      getInitialState: function() {
        return {
          news: [{
            id: "5",
            data: "I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
          }, {
            id: "6",
            data: "I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
          }, {
            id: "7",
            data: "I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
          }, {
            id: "8",
            data: "I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
          }, {
            id: "9",
            data: "I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
          }, ],
          length: null,
          height: 0
        }
      },
      componentWillMount: function() {},
      componentDidMount: function() {

        console.log(this.state.length)
        var lengthh = document.getElementById('newscontanier').children.length;
        console.log(lengthh);
        if(lengthh != this.state.length) {
          this.setState({
            length: lengthh //Still  null
          })
        }
      },
      render: function() {
        var newsdata = this.state.news.map(function(newss) {
            return( < NewsDetail key = {
                newss.id
              } {...newss
              }
              />)
            });
          return(<div className="newscontanier" id="newscontanier">{newsdata}</div>)
        }
      })
EN

回答 1

Stack Overflow用户

发布于 2016-08-31 01:48:35

这里只有一个语法错误,删除jsx -

代码语言:javascript
复制
 return (
    <div className="newscontanier" id="newscontanier">{newsdata}</div>
 );

请参阅此处的工作副本- https://jsfiddle.net/69z2wepo/54531/

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

https://stackoverflow.com/questions/39233662

复制
相关文章

相似问题

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