Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions examples/draft-0-10-0/tex/js/components/TeXBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (prevProps.content !== this.props.content) {
this._update();
}
}

componentWillUnmount() {
clearTimeout(this._timer);
this._timer = null;
}

render() {
return <div ref="container" onClick={this.props.onClick} />;
}
Expand Down
26 changes: 7 additions & 19 deletions examples/draft-0-9-1/tex/js/components/TeXBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth calling out there's an unused prevState second argument here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change but is that necessary?
The third snapshot argument is also unused.

And the docs for typical usage of componentDidUpdate don't include it either
https://reactjs.org/docs/react-component.html#componentdidupdate

if (prevProps.content !== this.props.content) {
this._update();
}
}

componentWillUnmount() {
clearTimeout(this._timer);
this._timer = null;
}

render() {
return (
<div
Expand Down
1 change: 0 additions & 1 deletion src/component/base/DraftEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {

componentDidUpdate(): void {
this._blockSelectEvents = false;
// moving this here, when it was previously set in componentWillUpdate
this._latestEditorState = this.props.editorState;
this._latestCommittedEditorState = this.props.editorState;
}
Expand Down
1 change: 0 additions & 1 deletion website/static/lib/Draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -10084,7 +10084,6 @@ var DraftEditor = function (_React$Component2) {

DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
this._blockSelectEvents = false;
// moving this here, when it was previously set in componentWillUpdate
this._latestEditorState = this.props.editorState;
this._latestCommittedEditorState = this.props.editorState;
};
Expand Down