I am learning Reactjs. I implemented one application for testing with rails. I have a search in lots to find a solution, but I did not find it. I wanted to call another component from the onClick function. But nothing happens. Is it possible what I'm trying to achieve? If yes, then please indicate to me where I am mistaken, and if not, in what way I can implement. Here is my code:
var Comment = React.createClass({ render: function () { return ( <div id={"comment_"+ this.props.id }> <h4>{ this.props.author } said:</h4> <p>{ this.props.desc }</p> <a href='' onClick={this.handleDelete}>Delete</a> | #this is for delete which works great <a href='' onClick={this.handleEdit}>Edit</a> # If I put here then it works fine <UpdateComments comments={ this.props} /> but I don't want it here </div> ) }, handleDelete: function(event) { $.ajax({ url: '/comments/'+ this.props.id, type: "DELETE", dataType: "json", success: function (data) { this.setState({ comments: data }); }.bind(this) }); }, handleEdit: function(event) { var Temp = React.createClass({ render: function(event){ return(<div> <UpdateComments comments={ this.props} /> #here I want to call UpdateComments component </div> ) } }); } });
Update: If I try the trick below, then it calls the component, but reloads the page and the called component disappears again :(
handleEdit: function() { React.render(<UpdateComments comments={ this.props} /> , document.getElementById('comment_'+ this.props.id)); }
Any other details if you need, feel free to ask. Thank you in advance.:)
source share