From b13b89c7ce4104c7729675b5affbee4ebc014206 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 7 Mar 2019 13:06:02 +0100 Subject: [PATCH 1/2] Fix JSON-editor --- src/components/layers/JSONEditor.jsx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/components/layers/JSONEditor.jsx b/src/components/layers/JSONEditor.jsx index 2204623..0ed66d3 100644 --- a/src/components/layers/JSONEditor.jsx +++ b/src/components/layers/JSONEditor.jsx @@ -29,20 +29,11 @@ class JSONEditor extends React.Component { } } - static getDerivedStateFromProps(props, state) { - return { - code: JSON.stringify(props.layer, null, 2) - }; - } - - shouldComponentUpdate(nextProps, nextState) { - try { - const parsedLayer = JSON.parse(this.state.code) - // If the structure is still the same do not update - // because it affects editing experience by reformatting all the time - return nextState.code !== JSON.stringify(parsedLayer, null, 2) - } catch(err) { - return true + componentDidUpdate(prevProps, prevState) { + if (prevProps.layer !== this.props.layer) { + this.setState({ + code: JSON.stringify(this.props.layer, null, 2) + }) } } From 1fbfa8428b26f2af9fbf7411316f802fa6052086 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 7 Mar 2019 13:47:53 +0100 Subject: [PATCH 2/2] Remove unused argument --- src/components/layers/JSONEditor.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/layers/JSONEditor.jsx b/src/components/layers/JSONEditor.jsx index 0ed66d3..2f01b82 100644 --- a/src/components/layers/JSONEditor.jsx +++ b/src/components/layers/JSONEditor.jsx @@ -29,7 +29,7 @@ class JSONEditor extends React.Component { } } - componentDidUpdate(prevProps, prevState) { + componentDidUpdate(prevProps) { if (prevProps.layer !== this.props.layer) { this.setState({ code: JSON.stringify(this.props.layer, null, 2)