Skip to content

Commit 40db517

Browse files
cbergmilleragirton
authored andcommitted
[FIX] JedWatson#1651 moved option prop sync to componentWillReceiveProps (JedWatson#1765)
* [FIX] JedWatson#1651 moved option prop sync to componentWillReceiveProps * [ADD] test for option prop sync by componentWillReceiveProps
1 parent 1d15068 commit 40db517

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/Async.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,12 @@ export default class Async extends Component {
6868
}
6969
}
7070

71-
componentWillUpdate (nextProps, nextState) {
72-
const propertiesToSync = ['options'];
73-
propertiesToSync.forEach((prop) => {
74-
if (this.props[prop] !== nextProps[prop]) {
75-
this.setState({
76-
[prop]: nextProps[prop]
77-
});
78-
}
79-
});
71+
componentWillReceiveProps(nextProps) {
72+
if (nextProps.options !== this.props.options) {
73+
this.setState({
74+
options: nextProps.options,
75+
});
76+
}
8077
}
8178

8279
clearOptions() {

test/Async-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,20 @@ describe('Async', () => {
447447
expect(input, 'to equal', document.activeElement);
448448
});
449449
});
450+
451+
452+
describe('props sync test', () => {
453+
it('should update options on componentWillReceiveProps', () => {
454+
createControl({
455+
});
456+
asyncInstance.componentWillReceiveProps({
457+
options: [{
458+
label: 'bar',
459+
value: 'foo',
460+
}]
461+
});
462+
expect(asyncNode.querySelectorAll('[role=option]').length, 'to equal', 1);
463+
expect(asyncNode.querySelector('[role=option]').textContent, 'to equal', 'bar');
464+
});
465+
});
450466
});

0 commit comments

Comments
 (0)