From 3e1188215d73a219b040cb654e5c7817bb79a611 Mon Sep 17 00:00:00 2001 From: Max Rabelo Do Nascimento Date: Thu, 3 Oct 2019 09:13:11 -0300 Subject: [PATCH 1/2] rerender default values --- src/TagSelect.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/TagSelect.js b/src/TagSelect.js index d4e1a8a..5025224 100644 --- a/src/TagSelect.js +++ b/src/TagSelect.js @@ -60,6 +60,15 @@ class TagSelect extends React.Component { this.setState({ value }) } + componentDidUpdate (prevProps) { + if (prevProps !== this.props) { + const value = {} + this.props.value.forEach((val) => { + value[val[[this.props.keyAttr]] || val] = val + }) + this.props.value = value; + } + } /** * @description Return the number of items selected * @return {Number} From 41094494b16a55956e279c80fcbed1102baf4358 Mon Sep 17 00:00:00 2001 From: Max Rabelo Do Nascimento Date: Mon, 7 Oct 2019 12:57:24 -0300 Subject: [PATCH 2/2] rerender default values setState --- src/TagSelect.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TagSelect.js b/src/TagSelect.js index 5025224..f7c7d11 100644 --- a/src/TagSelect.js +++ b/src/TagSelect.js @@ -58,17 +58,18 @@ class TagSelect extends React.Component { }) this.setState({ value }) - } + } - componentDidUpdate (prevProps) { + componentDidUpdate(prevProps) { if (prevProps !== this.props) { const value = {} this.props.value.forEach((val) => { value[val[[this.props.keyAttr]] || val] = val }) - this.props.value = value; + this.setState({ value }) } } + /** * @description Return the number of items selected * @return {Number} @@ -101,7 +102,6 @@ class TagSelect extends React.Component { const value = { ...this.state.value } const found = this.state.value[key] - // Item is on array, so user is removing the selection if (found) { delete value[key] @@ -115,7 +115,7 @@ class TagSelect extends React.Component { value[key] = item } - + return this.setState({ value }, () => { if (this.props.onItemPress) { this.props.onItemPress(item)