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

Commit

Permalink
Remove componentWillReceiveProps usages in examples (#1952)
Browse files Browse the repository at this point in the history
Summary:
**Summary**
Resolves [1940](#1940)
Change usage of `componentWillReceiveProps` in Tex examples to `componentDidUpdate`
Pull Request resolved: #1952

Reviewed By: claudiopro

Differential Revision: D13417818

Pulled By: claudiopro

fbshipit-source-id: b13ff3140c3207cddaeb8d98c239f7dfd4b04a47
  • Loading branch information
Deep authored and facebook-github-bot committed Jan 21, 2019
1 parent 9b2a366 commit 363f66e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 44 deletions.
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 @@ -449,7 +449,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 @@ -9954,7 +9954,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

0 comments on commit 363f66e

Please sign in to comment.