Skip to content

Commit 1a9005e

Browse files
committed
fix reset dataSet
1 parent 47aa264 commit 1a9005e

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

example/components/LocalDataSetExample.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export const LocalDataSetExample = memo(() => {
1616
closeOnBlur={false}
1717
initialValue={{ id: '2' }} // or just '2'
1818
onSelectItem={setSelectedItem}
19-
dataSet={dataSet}
19+
// dataSet={dataSet}
20+
dataSet={[
21+
{ id: '1', title: 'Alpha' },
22+
{ id: '2', title: 'Beta' },
23+
{ id: '3', title: 'Gamma' }
24+
]}
2025
ItemSeparatorComponent={<View style={{ height: 1, width: '100%', backgroundColor: '#d8e1e6' }} />}
2126
getItemLayout={(data, index) => ({ length: 50, offset: 50 * index, index })}
2227
/>

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-autocomplete-dropdown",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Dropdown Item picker with search and autocomplete (typeahead) functionality for react native",
55
"main": "src/index.js",
66
"typings": "src/index.d.ts",

src/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const AutocompleteDropdown = memo(
4444
}, [inputRef])
4545

4646
useEffect(() => {
47+
// VirtualizedLists should never be nested inside plain ScrollViews with the same orientation because it can break windowing and other functionality - use another VirtualizedList-backed container instead.
4748
LogBox.ignoreLogs(['VirtualizedLists should never be nested'])
4849
}, [])
4950

@@ -73,10 +74,6 @@ export const AutocompleteDropdown = memo(
7374
}
7475
}, [isOpened, props.controller])
7576

76-
useEffect(() => {
77-
setDataSet(props.dataSet)
78-
}, [props.dataSet])
79-
8077
useEffect(() => {
8178
if (selectedItem) {
8279
setSearchText(selectedItem.title ?? '')
@@ -103,7 +100,6 @@ export const AutocompleteDropdown = memo(
103100

104101
const _onSelectItem = useCallback(item => {
105102
setSelectedItem(item)
106-
107103
inputRef.current.blur()
108104
setIsOpened(false)
109105
}, [])
@@ -151,7 +147,16 @@ export const AutocompleteDropdown = memo(
151147
}
152148

153149
useEffect(() => {
154-
if (!Array.isArray(props.dataSet) || props.useFilter === false || !searchText.length) {
150+
setDataSet(props.dataSet)
151+
}, [props.dataSet])
152+
153+
useEffect(() => {
154+
if (!searchText.length) {
155+
setDataSet(props.dataSet)
156+
return
157+
}
158+
159+
if (!Array.isArray(props.dataSet) || props.useFilter === false) {
155160
return
156161
}
157162

@@ -340,8 +345,10 @@ AutocompleteDropdown.propTypes = {
340345
suggestionsListTextStyle: PropTypes.object,
341346
ChevronIconComponent: PropTypes.element,
342347
ClearIconComponent: PropTypes.element,
348+
ScrollViewComponent: PropTypes.elementType,
343349
EmptyResultComponent: PropTypes.element,
344-
emptyResultText: PropTypes.string
350+
emptyResultText: PropTypes.string,
351+
flatListProps: PropTypes.object
345352
}
346353

347354
const styles = ScaledSheet.create({

0 commit comments

Comments
 (0)