Skip to content

Commit 9e69257

Browse files
committed
feat: Optimize preformance issue.
1 parent 4554dcf commit 9e69257

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/components/CodeMirror/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ export default class ReactCodeMirror extends Component<ICodeMirror> {
113113

114114
this.renderCodeMirror(this.props);
115115
}
116-
117-
public async componentWillReceiveProps(nextPros: ICodeMirror) {
118-
this.renderCodeMirror(nextPros);
116+
public UNSAFE_componentWillReceiveProps(nextPros: ICodeMirror) {
117+
if (nextPros.value !== this.props.value || nextPros.width !== this.props.width || nextPros.height !== this.props.height) {
118+
this.renderCodeMirror(nextPros);
119+
}
119120
}
120121

121122
// 将props中所有的事件处理函数映射并保存

src/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ export interface IMarkdownEditor extends IProps, ICodeMirror {
1919
options?: CodeMirror.EditorConfiguration,
2020
}
2121

22-
interface IMarkdownEditorState {
23-
fullscreen: boolean;
24-
}
22+
interface IMarkdownEditorState { }
2523

26-
export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor, IMarkdownEditorState, {}> {
24+
export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor, IMarkdownEditorState> {
2725
public static displayName = 'MarkdownEditor';
2826
public static defaultProps: IMarkdownEditor = {
2927
onChange: () => null,

0 commit comments

Comments
 (0)