Skip to content

Instantly share code, notes, and snippets.

@julianlconnor
Last active August 29, 2015 14:00
Show Gist options
  • Save julianlconnor/704f612e8d47cbe7dd3c to your computer and use it in GitHub Desktop.
Save julianlconnor/704f612e8d47cbe7dd3c to your computer and use it in GitHub Desktop.
findRenderedComponentWithType example
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