Last active
December 18, 2015 01:19
-
-
Save camspiers/5703214 to your computer and use it in GitHub Desktop.
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
/** @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