From edb890406166d418afce1cf01e7c04469fe959ad Mon Sep 17 00:00:00 2001 From: Bigood Date: Thu, 5 Mar 2020 10:19:36 +0100 Subject: [PATCH] Test undefinedness of value in getSelectedItem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using itemKey to select a default value, if using a placeholder without a value (which is intended), internal method getSelectedItem fails as it doesn't test the presence of an item.value before calling isEqual, and in absence of a value prop on Picker, will resolve as isEqual(undefined, undefined). Thus, this code won't work, but should IMO: const items = [ { key: 'a', label: 'a', value: 'a' }, { key: 'b', label: 'b', value: 'b' }, { key: 'c', label: 'c', value: 'c' }, ] ... A simple non-breaking change in getSelectedItem will correct this, as proposed in this pull request. See this snack for a most comprehensive demonstration of this unexpected behavior: https://snack.expo.io/rJm7QrAEU --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index ddbb5d25..b71d5a6f 100644 --- a/src/index.js +++ b/src/index.js @@ -103,7 +103,10 @@ export default class RNPickerSelect extends PureComponent { if (item.key && key) { return isEqual(item.key, key); } - return isEqual(item.value, value); + if(item.value && value){ + return isEqual(item.value, value); + } + return false }); if (idx === -1) { idx = 0;