how to build whatsapp clone using react native
- User
how to build whatsapp clone using react native
- Assistant
To build a WhatsApp clone using React Native, you can follow these steps:
- User
can write the code
- Assistant
Certainly! Here is an example code snippet to get you started with building a simple WhatsApp clone using React Native:
import React, { useState } from 'react'; import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native'; const App = () => { const [message, setMessage] = useState(''); const [chat, setChat] = useState([]); const sendMessage = () => { if (message !== '') { const newChat = [...chat, message]; setChat(newChat); setMessage(''); } }; return ( <View style={styles.container}> <View style={styles.chatContainer}> {chat.map((message, index) => ( <Text key={index} style={styles.messageText}>{message}</Text> ))} </View> <View style={styles.inputContainer}> <TextInput style={styles.messageInput} placeholder="Type your message..." value={message} onChangeText={setMessage} /> <TouchableOpacity style={styles.sendButton} onPress={sendMessage}> <Text style={styles.sendButtonText}>Send</Text> </TouchableOpacity> </View> </View> ); }; const styles = StyleSheet.create({ container: { flex: 1, padding: 20, justifyContent: 'center', backgroundColor: '#f0f0f0', }, chatContainer: { flex: 1, justifyContent: 'flex-end', marginBottom: 20, }, messageText: { fontSize: 16, padding: 10, backgroundColor: 'white', borderRadius: 10, marginBottom: 10, }, inputContainer: { flexDirection:'row', alignItems: 'center', }, messageInput: { flex: 1, padding: 10, backgroundColor: 'white', borderRadius: 10, marginRight: 10, }, sendButton: { backgroundColor: 'blue', paddingVertical: 10, paddingHorizontal: 20, borderRadius: 10, }, sendButtonText: { color: 'white', fontSize: 16, fontWeight: 'bold', }, }); export default App;