using props, not state for selected

This commit is contained in:
Belen Curcio
2017-10-10 12:40:09 -03:00
parent 1c535bda89
commit 2028e56f48
+1 -16
View File
@@ -10,27 +10,12 @@ class Dropdown extends React.Component {
constructor(props) {
super(props);
this.state = {
selected: {
label: props.label || '',
value: props.value || ''
},
isOpen: false
};
}
componentWillReceiveProps(newProps) {
if (newProps.value && newProps.value !== this.state.selected.value) {
this.setState({
selected: {
label: newProps.label,
value: newProps.value
}
});
}
}
fireChange = (newState) => {
if (newState.selected !== this.state.selected && this.props.onChange) {
if (this.props.onChange) {
this.props.onChange(newState.selected.value);
}
}