Skip to content

Commit 49cdf3c

Browse files
committed
fix(autocomplete): change data on update props
1 parent adee2d4 commit 49cdf3c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/autocomplete/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AutoComplete extends Component {
1717
*/
1818
this.state = {
1919
data: props.data,
20+
prevProps: props.data,
2021
input: { [`${props.labelKey}`]: '', [`${props.valueKey}`]: null },
2122
showSuggestions: false,
2223
blockOnBlur: false,
@@ -29,6 +30,16 @@ class AutoComplete extends Component {
2930
this.focusedElement = null;
3031
}
3132

33+
static getDerivedStateFromProps({ data }, state) {
34+
if (state && data !== state.prevProps) {
35+
return {
36+
data,
37+
prevProps: data,
38+
};
39+
}
40+
return null;
41+
}
42+
3243
getUpdatedData = (input) => {
3344
const { labelKey, data } = this.props;
3445
const inputlabel = input[`${labelKey}`].toLowerCase();

0 commit comments

Comments
 (0)