File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,27 @@ const styles = StyleSheet.create({
105105export 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments