Nane
Nane

Reputation: 403

How to Integrate jQuery with React js?

I badly need jQuery Api's, but the thing is I have use that api with React js. I am just confusing my React js Lifecycles. Additional Info I am creating view counter for different div. In my Point of View I badly need jQuery api's to take care the height, ScrollTop.. The following code will output Undefined

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"
              },

          ],
          top:0,
          height:null
      }
    },
    componentWillMount:function () {

    },
    componentDidUpdate:function () {

        var height = $('#newscontainer').height();
        alert(height)//udefined

    },
    render:function () {

      var newsdata = this.state.news.map(function (newss) {

          return(<NewsDetail key={newss.id} {...newss}/>)
      });
        return(
            <div className="newscontanier" id="newscontanier">{newsdata}</div>
        )



    }

})

Upvotes: 0

Views: 231

Answers (1)

alma
alma

Reputation: 126

You have typo newscontanier. Nonetheless you can do this like

<div ref={elem => this.elem = elem} className="newscontanier" id="newscontanier">{newsdata}</div>

and then you can find dom element

this.elem.getDOMNode();

Upvotes: 1

Related Questions