diff --git a/examples/draft-0-10-0/tex/js/components/TeXBlock.js b/examples/draft-0-10-0/tex/js/components/TeXBlock.js index 885c445328..59f29651a4 100644 --- a/examples/draft-0-10-0/tex/js/components/TeXBlock.js +++ b/examples/draft-0-10-0/tex/js/components/TeXBlock.js @@ -18,40 +18,24 @@ import katex from 'katex'; import React from 'react'; class KatexOutput extends React.Component { - constructor(props) { - super(props); - this._timer = null; - } - _update() { - if (this._timer) { - clearTimeout(this._timer); - } - - this._timer = setTimeout(() => { - katex.render( - this.props.content, - this.refs.container, - {displayMode: true}, - ); - }, 0); + katex.render( + this.props.content, + this.refs.container, + {displayMode: true}, + ); } componentDidMount() { this._update(); } - componentWillReceiveProps(nextProps) { - if (nextProps.content !== this.props.content) { + componentDidUpdate(prevProps, prevState) { + if (prevProps.content !== this.props.content) { this._update(); } } - componentWillUnmount() { - clearTimeout(this._timer); - this._timer = null; - } - render() { return
; } diff --git a/examples/draft-0-9-1/tex/js/components/TeXBlock.js b/examples/draft-0-9-1/tex/js/components/TeXBlock.js index e619a9c827..5c11dae688 100644 --- a/examples/draft-0-9-1/tex/js/components/TeXBlock.js +++ b/examples/draft-0-9-1/tex/js/components/TeXBlock.js @@ -21,38 +21,26 @@ import {Entity} from 'draft-js'; class KatexOutput extends React.Component { constructor(props) { super(props); - this._timer = null; } _update() { - if (this._timer) { - clearTimeout(this._timer); - } - - this._timer = setTimeout(() => { - katex.render( - this.props.content, - this.container, - {displayMode: true}, - ); - }, 0); + katex.render( + this.props.content, + this.container, + {displayMode: true}, + ); } componentDidMount() { this._update(); } - componentWillReceiveProps(nextProps) { - if (nextProps.content !== this.props.content) { + componentDidUpdate(prevProps, prevState) { + if (prevProps.content !== this.props.content) { this._update(); } } - componentWillUnmount() { - clearTimeout(this._timer); - this._timer = null; - } - render() { return (