Created
March 5, 2021 19:19
-
-
Save hayanisaid/3daee3c518bf64f270745c92be911551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copyright https://github.com/FaridSafi/react-native-gifted-chat | |
import {GiftedChat} from 'react-native-gifted-chat'; | |
import React, {useCallback,useState} from 'react'; | |
const App: () => React$Node = () => { | |
const [messages, setMessages] = React.useState([]); | |
React.useEffect(() => { | |
setMessages([ | |
{ | |
_id: 1, | |
text: 'Hello developer', | |
createdAt: new Date(), | |
user: { | |
_id: 2, | |
name: 'React Native', | |
avatar: 'https://placeimg.com/140/140/any', | |
}, | |
}, | |
]); | |
}, []); | |
const onSend = useCallback((messages = []) => { | |
setMessages((previousMessages) => | |
GiftedChat.append(previousMessages, messages), | |
); | |
}, []); | |
return ( | |
<> | |
<View style={styles.container}> | |
<StatusBar barStyle="dark-content" /> | |
<GiftedChat | |
messages={messages} | |
onSend={(messages) => onSend(messages)} | |
user={{ | |
_id: 1, | |
}} | |
/> | |
</View> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment