Now I'm not using JSX ( several reasons )
I'm able to work fine with React.createElement
e.g.
var ui =
React.createElement('div', {},
React.createElement('h1', {}, "Contacts"),
React.createElement('ul', {},
React.createElement('li', {},
React.createElement('h2', {}, "James Nelson"),
React.createElement('a', { href: 'mailto:james@json.com' }, 'james@json.com')
),
React.createElement('li', {},
React.createElement('h2', {}, "Joe Citizen"),
React.createElement('a', { href: 'mailto:joe@example.com' }, 'joe@example.com')
)
)
);
React.render(ui, document.getElementById('react-app'));
However, I started reading and seeing about the createClass but I'm getting this error
react-with-addons.min.js:20302 Uncaught Error: Invariant Violation: React.render(): Invalid component element. Instead of passing a component class, make sure to instantiate it by passing it to React.createElement.
Here is my sample code in which I'm just trying to set a variable "x" to html and then use it in the render: return x
What is wrong with this?
var x = "<div><select id='lang' onChange={this.change} value={this.state.value}>";
x = x + "<option value='select'>Select</option>";
x = x + "<option value='Java'>Java</option>";
x = x + "</select><p></p><p>{this.state.value}</p></div>";
var MySelect = React.createClass({
change: function(event){
this.setState({value: event.target.value});
},
render: function(){
return(
x
);
}
});
React.render(MySelect, document.getElementById('react-main'));
Ultimately my goal is to create a dropdown in which onchange it will use react to show/hide other elements ( textboxes etc... ) Question with Answer Type ....
UPDATE
I do see various React in the project
This code someone wrote and I assume it "works"
SS.OpportunityDetailsGraph= React.createClass({displayName: "OpportunityDetailsGraph",
componentDidMount: function(){
advisorDataManager.getOpportunityExceptionChart(this.props.opportunity.guid).done(this.renderChart);
},
renderChart:function(html){
var content = $(this.getDOMNode()).find("#opportunity-details");
content.html("").append(html).hide().fadeIn("slow");
},
render: function() {
return (
React.createElement("div", {className: "chart"},
React.createElement("div", {className: "ibox float-e-margins"},
React.createElement("div", {className: "ibox-content"},
React.createElement("div", {id: "opportunity-details"},
React.createElement(SS.Loader, null)
)
)
)
)
);
}
});