React Chat Application Tutorial
Prompt
import React, { useState } from 'react';
const App = () => {
const [messages, setMessages] = useState([]);
const [inputText, setInputText] = useState('');
const [userName, setUserName] = useState('');
const [userColor, setUserColor] = useState('#000000');
const handleSendMessage = () => {
if (inputText.trim()) {
const newMessage = {
id: messages.length + 1,
text: inputText,
userName,
userColor,
timestamp: new Date().toLocaleTimeString(),
};
setMessages([...messages, newMessage]);
setInputText('');
}
};
return (
<div className="min-h-screen bg-gray-100 p-6">
<div className="max-w-4xl mx-auto bg-white rounded-lg shadow-lg overflow-hidden">
<div className="p-6 border-b border-gray-200">
<h1 className="text-2xl font-bold text-gray-800">ChatGPT</h1>
</div>
<div className="p-6 space-y-4">
{messages.map((message) => (
<div key={message.id} className="flex space-x-4">
<div
className="w-10 h-10 rounded-full flex items-center justify-center text-white"
style={{ backgroundColor: message.userColor }}
>
{message.userName.charAt(0)}
</div>
<div className="flex-1">
<p className="text-sm text-gray-600 font-semibold">{message.userName}</p>
<p className="text-gray-800">{message.text}</p>
<p className="text-xs text-gray-500">{message.timestamp}</p>
</div>
</div>
))}
</div>
<div className="p-6 border-t border-gray-200">
<div className="flex space-x-4">
<input
type="text"
value={userName}
onChange={(e) => setUserName(e.target.value)}
placeholder="Your Name"
className="flex-1 p-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<input
type="color"
value={userColor}
onChange={(e) => setUserColor(e.target.value)}
className="w-12 h-12 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="mt-4 flex space-x-4">
<input
type="text"
value={inputText}
onChange={(e) => setInputText(e.target.value)}
placeholder="Type a message..."
className="flex-1 p-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<button
onClick={handleSendMessage}
className="px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
>
Send
</button>
</div>
</div>
</div>
</div>
);
};
export default App;
بعد ما تكتب الاسم بحولك الى القائمة الاصدقاء والمجموعاةGenerated Result
More Recommendations
View AllBuild XO App with AI
create a complete XO (Tic Tac Toe) app with AI opponent: "Build a modern, fully-featured Tic Tac Toe (XO) app that includes: A clean, user-friendly interface optimized for mobile, tablet, and web. Two-player mode: Player vs Player on the same device or online multiplayer (optional). Single-player mode: Play against an intelligent AI robot using advanced algorithms like Minimax to provide a challenging and fun experience. Multiple difficulty levels for the AI (easy, medium, hard). Score tracking and saving game results. Sound effects and animations for moves and game events. Quick restart/reset game functionality. Save and resume gameplay. Responsive and sleek design with customizable colors. Multi-language support including English and Arabic. Tutorial mode to teach new players how to play. Match history log for past games. Smooth and fast transitions and animations. Please generate the complete code in JavaScript/HTML/CSS with detailed explanations on how to implement the AI logic and all features.
Make a Snake Game
make a game snake
Fix React Fetch Code
please correct for me this code, no axios, post useEffect(() => { const fetchData = async () => { try { const response = await axios.get('https://www.technosysa.com/new_announce.php', { params: { id: idParam, mode: 'get_announce' }, headers: { 'Content-Type': 'application/json', } }); console.log(response.data); setItem( { id: idParam, description: response.data.description, Name_person: response.data.Name_person, telefono: response.data.telefono, whatsapp: response.data.whatsapp, email: response.data.email, file_path_user_jpg: file_path_user_jpg } ); } catch (error) { console.error('Error fetching data:', error.data); } }; fetchData(); });
MercadoPago Error Handling
how get more detail error json from id preference.update mercadopago with reack hooks
Get JSON Error Details
how get more detail error json from preference.update mercadopago with reack hooks
MercadoPago Error Details
how get more detail error json from preference.update mercadopago
