Skip to content

Commit 74479ff

Browse files
committed
chore: update readme example
1 parent d2cf99a commit 74479ff

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

README.md

+25-35
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Example
3030
```tsx
3131
import * as React from 'react';
3232
import { FC, useState } from 'react';
33-
import { Mentions, Suggestion } from 'react-native-controlled-mentions';
3433
import { Pressable, SafeAreaView, Text, View } from 'react-native';
34+
import { Mentions, MentionSuggestionsProps, Suggestion } from 'react-native-controlled-mentions';
3535

3636
const suggestions = [
3737
{id: '1', name: 'David Tabaka'},
@@ -41,34 +41,29 @@ const suggestions = [
4141
{id: '5', name: 'Grey'},
4242
];
4343

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+
}
4948

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+
}
7267

7368
const App = () => {
7469
const [value, setValue] = useState('Hello @[Mary](2)! How are you?');
@@ -79,13 +74,7 @@ const App = () => {
7974
value={value}
8075
onChange={setValue}
8176

82-
renderSuggestions={({keyword, onSuggestionPress}) => (
83-
<MentionSuggestions
84-
keyword={keyword}
85-
suggestions={suggestions}
86-
onSuggestionPress={onSuggestionPress}
87-
/>
88-
)}
77+
renderSuggestions={MentionSuggestions}
8978

9079
placeholder="Type here..."
9180
style={{padding: 12}}
@@ -149,4 +138,5 @@ Known issues
149138
* ~~Text becomes transparent when setting custom font size in TextInput~~ FIXED
150139

151140
[npm-image]: https://img.shields.io/npm/v/react-native-controlled-mentions
141+
152142
[npm-url]: https://npmjs.org/package/react-native-controlled-mentions

0 commit comments

Comments
 (0)