Created
November 21, 2014 21:24
-
-
Save bkonkle/9568b6acdf40a77d443d to your computer and use it in GitHub Desktop.
SafeStringComponent
This file contains hidden or 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 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