Skip to content

Commit 59505a4

Browse files
committed
Stop pushing null to the arr in search
1 parent d0c6d8a commit 59505a4

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-select-dropdown",
3-
"version": "3.3.4",
3+
"version": "3.4.0",
44
"description": "react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for andriod and iOS platforms.",
55
"main": "index.js",
66
"typings": "index.d.ts",

src/SelectDropdown.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DropdownWindow from './components/DropdownWindow';
1010
import {useSelectDropdown} from './hooks/useSelectDropdown';
1111
import {useLayoutDropdown} from './hooks/useLayoutDropdown';
1212
import {useRefs} from './hooks/useRefs';
13+
import {findIndexInArr} from './helpers/findIndexInArr';
1314

1415
const SelectDropdown = (
1516
{
@@ -116,9 +117,10 @@ const SelectDropdown = (
116117
}
117118
};
118119
const onSelectItem = (item, index) => {
120+
const indexInOriginalArr = findIndexInArr(item, data);
119121
closeDropdown();
120-
onSelect && onSelect(item, index);
121-
selectItem(index);
122+
onSelect && onSelect(item, indexInOriginalArr);
123+
selectItem(indexInOriginalArr);
122124
};
123125
/* ******************** Render Methods ******************** */
124126
const renderSearchView = () => {
@@ -143,7 +145,8 @@ const SelectDropdown = (
143145
);
144146
};
145147
const renderFlatlistItem = ({item, index}) => {
146-
const isSelected = index == selectedIndex;
148+
const selectedItemIndex = findIndexInArr(selectedItem, dataArr);
149+
const isSelected = index == selectedItemIndex;
147150
return (
148151
isExist(item) && (
149152
<TouchableOpacity

src/helpers/deepSearchInArr.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export const deepSearchInArr = (query, arr) => {
2424
for (let i = 0; i <= arr.length - 1; i++) {
2525
if (contains(arr[i], query)) {
2626
array.push(arr[i]);
27-
} else {
28-
array.push(null);
2927
}
3028
if (i == arr.length - 1) {
3129
return array;

src/hooks/useSelectDropdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const useSelectDropdown = (data, defaultValueByIndex, defaultValue, disab
1313
if (!data || data.length == 0) {
1414
reset();
1515
}
16-
}, [data]);
16+
}, [JSON.stringify(data)]);
1717

1818
// default value by index added or changed
1919
useEffect(() => {
@@ -23,7 +23,7 @@ export const useSelectDropdown = (data, defaultValueByIndex, defaultValue, disab
2323
selectItem(defaultValueByIndex);
2424
}
2525
}
26-
}, [defaultValueByIndex]);
26+
}, [JSON.stringify(defaultValueByIndex)]);
2727
// default value added or changed
2828
useEffect(() => {
2929
// defaultValue may be equals zero
@@ -32,14 +32,14 @@ export const useSelectDropdown = (data, defaultValueByIndex, defaultValue, disab
3232
selectItem(findIndexInArr(defaultValue, data));
3333
}
3434
}
35-
}, [defaultValue]);
35+
}, [JSON.stringify(defaultValue)]);
3636

3737
const dataArr = useMemo(() => {
3838
if (disabledInternalSearch) {
3939
return data;
4040
}
4141
return searchTxt ? deepSearchInArr(searchTxt, data) : data;
42-
}, [data, searchTxt]);
42+
}, [JSON.stringify(data), searchTxt]);
4343

4444
const selectItem = index => {
4545
setSelectedItem(data[index]);

0 commit comments

Comments
 (0)