Skip to content

Commit 5e326de

Browse files
update readme, use destructurization
1 parent 62061c4 commit 5e326de

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@ const styles = StyleSheet.create({
105105
export default withKeyboardAwareScrollView(HomeScreen);
106106
```
107107

108+
## Usage without data-driven content
109+
You can also pass fixed array of items to the Autocomplete
110+
```javascript
111+
const data = [
112+
"Apples",
113+
"Broccoli",
114+
"Chicken",
115+
"Duck",
116+
"Eggs",
117+
"Fish",
118+
"Granola",
119+
"Hash Browns",
120+
];
121+
```
122+
123+
Change valueExtractor and pass the data to Autocomplete without fetchDataUrl
124+
```javascript
125+
<Autocomplete data={data} valueExtactor={item => item} />
126+
```
127+
128+
108129
## Properties
109130

110131
name | description | type | default

components/Autocomplete/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Autocomplete extends Component {
5656
}
5757

5858
async triggerChange() {
59-
const {inputValue} = this.state;
59+
const {inputValue, items} = this.state;
6060
const {fetchDataUrl, valueExtractor} = this.props;
6161
if (fetchDataUrl) {
6262
try {
@@ -73,7 +73,7 @@ class Autocomplete extends Component {
7373
throw new Error(error);
7474
}
7575
} else {
76-
const filteredItems = this.state.items.filter(item => {
76+
const filteredItems = items.filter(item => {
7777
return (
7878
valueExtractor(item)
7979
.toLowerCase()
@@ -108,9 +108,10 @@ class Autocomplete extends Component {
108108
}
109109

110110
componentDidMount() {
111+
const {data} = this.props;
111112
this.mounted = true;
112-
if (this.props.data) {
113-
this.setState({items: this.props.data});
113+
if (data) {
114+
this.setState({items: data});
114115
}
115116
}
116117

0 commit comments

Comments
 (0)