JoeRoddy / react-native-tag-autocomplete

React Native Tag Autocompletion
69 stars 26 forks source link

Incompatible with react-native-autocomplete-input 5.x #57

Open zedtux opened 1 year ago

zedtux commented 1 year ago

After having upgraded all my dependencies, including this library and its dependency react-native-autocomplete-input, I'm facing the following error :

Error: Objects are not valid as a React child (found: object with keys {id, first_name, last_name, locale, code, trigram, _model, name}). If you meant to render a collection of children, use an array instead.

This is due to the fact that since version 5.x of react-native-autocomplete-input, the renderItem has been moved within the flatListProps like so :

diff --git a/node_modules/react-native-tag-autocomplete/index.js b/node_modules/react-native-tag-autocomplete/index.js
index 291f3e0..95b8aab 100644
--- a/node_modules/react-native-tag-autocomplete/index.js
+++ b/node_modules/react-native-tag-autocomplete/index.js
@@ -122,15 +122,17 @@ export default class AutoTags extends Component {
           onSubmitEditing={this.onSubmitEditing}
           multiline={true}
           autoFocus={this.props.autoFocus === false ? false : true}
-          renderItem={({ item, i }) => (
-            <TouchableOpacity onPress={e => this.addTag(item)}>
-              {this.props.renderSuggestion ? (
-                this.props.renderSuggestion(item)
-              ) : (
-                <Text>{item.name}</Text>
-              )}
-            </TouchableOpacity>
-          )}
+          flatListProps={{
+            renderItem: ({ item, i }) => (
+              <TouchableOpacity onPress={e => this.addTag(item)}>
+                {this.props.renderSuggestion ? (
+                  this.props.renderSuggestion(item)
+                ) : (
+                  <Text>{item.name}</Text>
+                )}
+              </TouchableOpacity>
+            )
+          }}
           inputContainerStyle={
             this.props.inputContainerStyle || styles.inputContainerStyle
           }

With this update, this library is compatible with react-native-autocomplete-input 5.x.

Either this lib should stick to the react-native-autocomplete-input 4.2.x version or be patched with the above.