Last active
August 29, 2015 14:00
-
-
Save julianlconnor/704f612e8d47cbe7dd3c to your computer and use it in GitHub Desktop.
findRenderedComponentWithType example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ExampleComponent = React.createClass({ | |
getInitialState: function() { | |
return { | |
shouldDisplayElement: true | |
} | |
}, | |
toggle: function() { | |
this.setState({ | |
shouldDisplayElement: !this.state.shouldDisplayElement | |
}); | |
}, | |
render: function() { | |
/** | |
* This element is subject to change. It could become a wrapper element, or even its own Component. | |
* It makes more sense in this scenario to refer to it by its ref rather than class. | |
*/ | |
var element = <span ref="fruit" className="banana">I am a banana.</span>; | |
return ( | |
<div onClick={this.toggle}> | |
{ this.state.shouldDisplayElement ? element : <span /> } | |
</div> | |
); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment