Want to do onClick change element in ReactJS. If I understand your questions correctly, you want to render a different element in case of an “onClick” event. This is a great use case for react states.
Take the following example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
React.createClass({ getInitialState : function() { return { showMe : false }; }, onClick : function() { this.setState({ showMe : true} ); }, render : function() { if(this.state.showMe) { return (<div> one div </div>); } else { return (<a onClick={this.onClick}> press me </a>); } } }) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.