Skip to content

Instantly share code, notes, and snippets.

@hayanisaid
Created March 5, 2021 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayanisaid/3daee3c518bf64f270745c92be911551 to your computer and use it in GitHub Desktop.
Save hayanisaid/3daee3c518bf64f270745c92be911551 to your computer and use it in GitHub Desktop.
# 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