@@ -30,8 +30,8 @@ Example
30
30
``` tsx
31
31
import * as React from ' react' ;
32
32
import { FC , useState } from ' react' ;
33
- import { Mentions , Suggestion } from ' react-native-controlled-mentions' ;
34
33
import { Pressable , SafeAreaView , Text , View } from ' react-native' ;
34
+ import { Mentions , MentionSuggestionsProps , Suggestion } from ' react-native-controlled-mentions' ;
35
35
36
36
const suggestions = [
37
37
{id: ' 1' , name: ' David Tabaka' },
@@ -41,34 +41,29 @@ const suggestions = [
41
41
{id: ' 5' , name: ' Grey' },
42
42
];
43
43
44
- type MentionSuggestionsProps = {
45
- keyword? : string ;
46
- suggestions: Suggestion [];
47
- onSuggestionPress: (suggestion : Suggestion ) => void ;
48
- };
44
+ const MentionSuggestions: FC <MentionSuggestionsProps > = ({keyword , onSuggestionPress }) => {
45
+ if (keyword == null ) {
46
+ return null ;
47
+ }
49
48
50
- const MentionSuggestions: FC <MentionSuggestionsProps > = (
51
- {
52
- keyword ,
53
- suggestions ,
54
- onSuggestionPress ,
55
- },
56
- ) => keyword != null ? (
57
- <View >
58
- { suggestions
59
- .filter (item => item .name .toLowerCase ().includes (keyword .toLowerCase ()))
60
- .map (suggestion => (
61
- <Pressable
62
- key = { suggestion .id }
63
- style = { {padding: 12 }}
64
- onPress = { () => onSuggestionPress (suggestion )}
65
- >
66
- <Text >{ suggestion .name } </Text >
67
- </Pressable >
68
- ))
69
- }
70
- </View >
71
- ) : null ;
49
+ return (
50
+ <View >
51
+ { users
52
+ .filter (one => one .name .toLocaleLowerCase ().includes (keyword .toLocaleLowerCase ()))
53
+ .map (one => (
54
+ <Pressable
55
+ key = { one .id }
56
+ onPress = { () => onSuggestionPress (one )}
57
+
58
+ style = { {padding: 12 }}
59
+ >
60
+ <Text >{ one .name } </Text >
61
+ </Pressable >
62
+ ))
63
+ }
64
+ </View >
65
+ );
66
+ }
72
67
73
68
const App = () => {
74
69
const [value, setValue] = useState (' Hello @[Mary](2)! How are you?' );
@@ -79,13 +74,7 @@ const App = () => {
79
74
value = { value }
80
75
onChange = { setValue }
81
76
82
- renderSuggestions = { ({keyword , onSuggestionPress }) => (
83
- <MentionSuggestions
84
- keyword = { keyword }
85
- suggestions = { suggestions }
86
- onSuggestionPress = { onSuggestionPress }
87
- />
88
- )}
77
+ renderSuggestions = { MentionSuggestions }
89
78
90
79
placeholder = " Type here..."
91
80
style = { {padding: 12 }}
@@ -149,4 +138,5 @@ Known issues
149
138
* ~~ Text becomes transparent when setting custom font size in TextInput~~ FIXED
150
139
151
140
[ npm-image ] : https://img.shields.io/npm/v/react-native-controlled-mentions
141
+
152
142
[ npm-url ] : https://npmjs.org/package/react-native-controlled-mentions
0 commit comments