Skip to content

Commit e46f765

Browse files
committed
Trigger onChangeValue event only when requested
1 parent 9c1f13b commit e46f765

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class CustomPicker extends React.PureComponent<
113113
{options.map((o, index) => (
114114
<TouchableOpacity
115115
onPress={() => {
116-
this.selectOption(o)
116+
this.selectOption(o, true)
117117
}}
118118
key={index}
119119
>
@@ -139,13 +139,13 @@ export class CustomPicker extends React.PureComponent<
139139
componentDidMount() {
140140
const { value, defaultValue } = this.props
141141
if (value || defaultValue) {
142-
this.selectOption(value || defaultValue)
142+
this.selectOption(value || defaultValue, false)
143143
}
144144
}
145145

146146
componentWillReceiveProps(nextProps: CustomPickerProps) {
147147
if (nextProps.value !== this.props.value) {
148-
this.selectOption(nextProps.value)
148+
this.selectOption(nextProps.value, false)
149149
}
150150
}
151151

@@ -181,11 +181,11 @@ export class CustomPicker extends React.PureComponent<
181181
* Select an option.
182182
* @param selectedItem Item/option to select.
183183
*/
184-
selectOption(selectedItem: any) {
184+
selectOption(selectedItem: any, triggerEvent: boolean) {
185185
const { onValueChange } = this.props
186186
this.setState({ selectedItem }, () => {
187187
this.hideOptions()
188-
if (onValueChange) {
188+
if (triggerEvent && onValueChange) {
189189
onValueChange(selectedItem)
190190
}
191191
})
@@ -196,7 +196,7 @@ export class CustomPicker extends React.PureComponent<
196196
*/
197197
clear() {
198198
const { defaultValue } = this.props
199-
this.selectOption(defaultValue || null)
199+
this.selectOption(defaultValue || null, true)
200200
}
201201
}
202202

0 commit comments

Comments
 (0)