Skip to content

Commit 462904a

Browse files
committed
chore: Handle UNSAFE_componentWillReceiveProps worning. #25
1 parent c634512 commit 462904a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ export default class MarkdownPreview extends Component<IMarkdownPreviewProps, IM
4848
componentDidMount() {
4949
this.highlight();
5050
}
51-
UNSAFE_componentWillReceiveProps(nextProps: IMarkdownPreviewProps) {
52-
if (nextProps.source !== this.props.source) {
53-
this.setState({ value: nextProps.source }, () => {
51+
componentDidUpdate(prevProps: IMarkdownPreviewProps) {
52+
if (this.props.source !== prevProps.source) {
53+
this.setState({ value: this.props.source }, () => {
5454
this.highlight();
5555
});
5656
}
5757
}
58-
public shouldComponentUpdate(nextProps: IMarkdownPreviewProps, nextState: IMarkdownPreviewState) {
59-
return nextProps.source !== this.props.source
60-
|| nextState.value !== this.state.value;
61-
}
6258
public renderHTML(mdStr?: string) {
6359
this.setState({ value: mdStr }, () => {
6460
this.highlight();

website/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import './App.css';
77
import MarkdownPreview from '../';
88
import MDStr from '../README.md';
99

10+
let val = 1;
11+
1012
export default () => {
1113
const [value, setValue] = useState('');
1214
return (
@@ -21,6 +23,9 @@ export default () => {
2123
React component preview markdown text in web browser. The minimal amount of CSS to replicate the GitHub Markdown style.
2224
</p>
2325
</header>
26+
<button onClick={() => {
27+
setValue('# 333' + val++)
28+
}}>set value</button>
2429
<div className="App-editor">
2530
<textarea
2631
placeholder="Please enter the Markdown code!"

0 commit comments

Comments
 (0)