Simple react render is not working

- 1 answer

Ad

Here I am trying to display a simple dropdown.I come to know getInitialState also not working.I spent some hours on it.Can you please explain it? Thank you.

var dropdown = React.createClass({
getInitialState:function() {
console.log('tr1');
return {
  data2:[] 
};
},

componentDidMount: function() {
console.log('tr2');
$.get(this.props.source, function(result) {  

  if (this.isMounted()) { 
    this.setState({          
      data2:result.data,

    });
  }
}.bind(this));
},



render:function() {
console.log('tr1');
console.log(this.state.data2);
return (

<div>

    <h3>Select portfolio </h3> <br/>

    <select onChange = {this.handleSelectChange}>
    <option>any-select</option>


    </select>

</div>

);
}
    });

ReactDOM.render(<dropdown source="http://improwised.cgc.com/portfolios?token=yR225Y"   />, document.getElementById('hello1'));
Ad

Answer

Ad

Change dropdown to Dropdown, because it is React component and should start from uppercase letter

Tags vs. React Components

Example

Ad
source: stackoverflow.com
Ad