Merge pull request #501 from pathmapper/issue_484

Fix JSON-editor
This commit is contained in:
pathmapper 2019-04-16 07:05:43 +02:00 committed by GitHub
commit 1bb079f078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,20 +29,11 @@ class JSONEditor extends React.Component {
} }
} }
static getDerivedStateFromProps(props, state) { componentDidUpdate(prevProps) {
return { if (prevProps.layer !== this.props.layer) {
code: JSON.stringify(props.layer, null, 2) this.setState({
}; code: JSON.stringify(this.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
} }
} }