Skip to content

Commit d38abd1

Browse files
committed
Cleaned up isValueAnObject check
1 parent 3d4d93b commit d38abd1

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

components/autocomplete/Autocomplete.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,12 @@ const factory = (Chip, Input) => {
6868
isValueAnObject: false
6969
};
7070

71-
componentDidMount () {
72-
this.setIsValueAnObject();
73-
}
74-
7571
componentWillReceiveProps (nextProps) {
7672
if (!this.props.multiple) {
7773
this.setState({
7874
query: this.query(nextProps.value)
7975
});
8076
}
81-
82-
if (nextProps.multiple && this.props.value !== nextProps.value) {
83-
this.setIsValueAnObject();
84-
}
8577
}
8678

8779
shouldComponentUpdate (nextProps, nextState) {
@@ -251,7 +243,7 @@ const factory = (Chip, Input) => {
251243

252244
if (!vals) vals = [];
253245

254-
if (this.props.showSelectedWhenNotInSource && this.state.isValueAnObject) {
246+
if (this.props.showSelectedWhenNotInSource && this.isValueAnObject()) {
255247
return new Map(Object.entries(vals));
256248
}
257249

@@ -271,7 +263,7 @@ const factory = (Chip, Input) => {
271263
const source = this.source();
272264
const newValue = target === void 0 ? event.target.id : target;
273265

274-
if (this.state.isValueAnObject) {
266+
if (this.isValueAnObject()) {
275267
const newItem = Array.from(source).reduce((obj, [k, value]) => {
276268
if (k === newValue) {
277269
obj[k] = value;
@@ -291,18 +283,16 @@ const factory = (Chip, Input) => {
291283

292284
values.delete(key);
293285

294-
if (this.state.isValueAnObject) {
286+
if (this.isValueAnObject()) {
295287
return this.handleChange(this.mapToObject(values), event);
296288
}
297289

298290
this.handleChange([...values.keys()], event);
299291
}
300292
}
301293

302-
setIsValueAnObject () {
303-
this.setState({
304-
isValueAnObject: !Array.isArray(this.props.value) && typeof this.props.value === 'object'
305-
});
294+
isValueAnObject () {
295+
return !Array.isArray(this.props.value) && typeof this.props.value === 'object';
306296
}
307297

308298
mapToObject (map) {

0 commit comments

Comments
 (0)