import React, {ReactElement, useState, useCallback, useEffect} from 'react';
import {GiftedChat, IMessage} from 'react-native-gifted-chat';
import styled from 'styled-components/native';
interface Props {}
const user = {
_id: 1,
name: 'Junghyun',
};
export default function ChattingRoomScreen({}: Props): ReactElement {
const [messages, setMessages] = useState<IMessage[]>();
useEffect(() => {
setMessages(msgData);
}, []);
const onSend = useCallback((msgArray = []) => {
setMessages(prevMessages => GiftedChat.append(prevMessages, msgArray));
}, []);
return (
<Container>
<GiftedChat
messages={messages}
onSend={msgs => onSend(msgs)}
user={user}
showAvatarForEveryMessage={true}
/>
</Container>
);
}
const Container = styled.SafeAreaView`
flex: 1;
`;
https://medium.com/@phylypo/react-native-simple-chat-with-firebase-and-giftedchat-f7dbdff2883a