CopyPastor

Detecting plagiarism made easy.

Score: 0.8262831568717957; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-07-24
by Kannan G

Original Post

Original - Posted on 2014-07-02
by Douglas



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Hope the below helps,
The key is to update the state of the component in the click handler using setState. When the state changes get applied, the render method gets called again with the new state:
var Detail = React.createClass({ getInitialState: function() { return { showResults: false }; }, onClick: function() { this.setState({ showResults: true }); }, render: function() { return ( <div> <input type="submit" value="Search" onClick={this.onClick} /> { this.state.showResults ? <Results /> : null } </div> ); } }); var DataRes = React.createClass({ render: function() { return ( <div id="data" className="search-results"> Some Data </div> ); } });
ReactDOM.render( <Detail /> , document.getElementById('container')); <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.2/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/15.6.2/react-dom.min.js"></script> <div id="container"> <!-- This element's contents will be replaced with your component. --> </div>

Happy Coding!
The key is to update the state of the component in the click handler using `setState`. When the state changes get applied, the `render` method gets called again with the new state:
<!-- begin snippet: js hide: false console: true babel: true -->
<!-- language: lang-js -->
var Search = React.createClass({ getInitialState: function() { return { showResults: false }; }, onClick: function() { this.setState({ showResults: true }); }, render: function() { return ( <div> <input type="submit" value="Search" onClick={this.onClick} /> { this.state.showResults ? <Results /> : null } </div> ); } });
var Results = React.createClass({ render: function() { return ( <div id="results" className="search-results"> Some Results </div> ); } });
ReactDOM.render( <Search /> , document.getElementById('container'));
<!-- language: lang-html -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.2/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/15.6.2/react-dom.min.js"></script>
<div id="container"> <!-- This element's contents will be replaced with your component. --> </div>
<!-- end snippet -->
[JSFiddle][1]

[1]: http://jsfiddle.net/kb3gN/15084/

        
Present in both answers; Present only in the new answer; Present only in the old answer;