Skip to content

Instantly share code, notes, and snippets.

@bkonkle
Created November 21, 2014 21:24
Show Gist options
  • Save bkonkle/9568b6acdf40a77d443d to your computer and use it in GitHub Desktop.
Save bkonkle/9568b6acdf40a77d443d to your computer and use it in GitHub Desktop.
SafeStringComponent
var React = require('react');
/**
* A more usable wrapper around React's dangerouslySetInnerHTML. This should only be used for
* safe server-provided data that cannot be manipulated by an external user. This will render
* HTML, so tags inside will become actual DOM elements.
*
* Do not abuse this.
*
* (╯°□°)╯︵ ┻━┻
*/
var SafeStringComponent = React.createClass({
propTypes: {
string: React.PropTypes.string
},
render: function() {
return <span dangerouslySetInnerHTML={{__html: this.props.string}}></span>;
}
});
module.exports = SafeStringComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment