Skip to content

Instantly share code, notes, and snippets.

@camspiers
Last active December 18, 2015 01:19
Show Gist options
  • Save camspiers/5703214 to your computer and use it in GitHub Desktop.
Save camspiers/5703214 to your computer and use it in GitHub Desktop.
/** @jsx React.DOM */
var MathJ = React.createClass({
shouldComponentUpdate: function (nextProps, nextState) {
return this.props.children !== nextProps.children;
},
componentDidMount: function (rootNode) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, rootNode]);
MathJax.Hub.Queue([function () {
rootNode.style.display = 'inline';
}]);
},
componentDidUpdate: function (prevProps, prevState, rootNode) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, rootNode]);
},
render: function () {
var style = {display: 'none'};
if (this.props.type === 'inline') {
return (
<span style={style}>{'\\(' + this.props.children + '\\)'}</span>
);
} else {
return (
<span style={style}>{'$$' + this.props.children + '$$'}</span>
);
}
}
});
window.MathJ = MathJ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment