Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Remove componentWillReceiveProps usages in examples #1952

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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, prevState) {
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, prevState) {
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