From 038de22b434cd1fb24053b4b97c58f75cd46454b Mon Sep 17 00:00:00 2001 From: danielsarin Date: Mon, 13 Nov 2017 21:48:23 +0200 Subject: [PATCH] fix calling onChange handler after Editor component unmount (#1399) --- packages/slate-react/src/components/editor.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/slate-react/src/components/editor.js b/packages/slate-react/src/components/editor.js index cb111ae4f..6edadb53d 100644 --- a/packages/slate-react/src/components/editor.js +++ b/packages/slate-react/src/components/editor.js @@ -157,6 +157,17 @@ class Editor extends React.Component { this.flushChange() } + /** + * When the component unmounts, clear flushTimeout if it has been set + * to avoid calling onChange after unmount. + */ + + componentWillUnmount = () => { + if (this.tmp.flushTimeout) { + clearTimeout(this.tmp.flushTimeout) + } + } + /** * Queue a `change` object, to be able to flush it later. This is required for * when a change needs to be applied to the value, but because of the React