-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
46 lines (40 loc) · 1.19 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { useState, useEffect, useCallback } from 'react';
import { Text, View, StyleSheet, SafeAreaView } from 'react-native';
import { GiftedChat } from 'react-native-gifted-chat'
import {geocode} from './utils/api'
export default function App() {
const [messages, setMessages] = useState([]);
const handleSubmit = async (location) => {
const coord = await geocode(location)
return JSON.stringify(coord)
}
useEffect(() => {
setMessages([
{
_id: 1,
text: 'Hello, my name is Aura! I can help you discover a location\'s historical crime data. Where do you want to go?',
createdAt: new Date(),
user: {
_id: 2,
name: 'Aura',
avatar: 'https://placeimg.com/140/140/any',
},
},
])
}, [])
const onSend = useCallback(async (messages = []) => {
console.log('messages', messages);
setMessages(previousMessages => GiftedChat.append(previousMessages, messages))
const coords = await handleSubmit(messages[0].text)
console.log(coords)
}, [])
return (
<GiftedChat
messages={messages}
onSend={messages => onSend(messages)}
user={{
_id: 1,
}}
/>
)
}