From 97c4d4e5f09c041fcdb25fa1f64bd5ae16baaccd Mon Sep 17 00:00:00 2001 From: Rishi8991 Date: Wed, 15 Apr 2020 23:30:58 +0100 Subject: [PATCH] Fix dynamic changing of n Hi, I came across an issue where if I want to dynamically change the value of n by the input of a form, then I get an error message as oldPoints do not exist or are not the same length as the newPoints. The above fix worked for me. --- src/components/Polygon.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/Polygon.js b/src/components/Polygon.js index cd199ae..53756d8 100644 --- a/src/components/Polygon.js +++ b/src/components/Polygon.js @@ -25,6 +25,14 @@ export default class Polygon extends Component { nextProps.n || this.props.n, nextProps.size || this.props.size, nextProps.ratios || this.props.ratios) + + if(this.state.oldPoints.length == 0 || this.state.oldPoints.length != newPoints.length) { + this.setState({ + oldPoints: newPoints, + currentPoints: newPoints + }) + return + } let isChanged = false for (let i = 0; i < newPoints.length; i++) {