- Home
- Code Library
- React Chat Application Tutorial
React Chat Application Tutorial
4.0
en
Programming
React
Chat Application
Frontend Development
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 ChatGPT-Like Web Interface
4.0
Software Development
en
AI Integration
Full-Stack Development
ChatGPT
UI Design
Backend Orchestration
You are a professional full-stack developer AI with deep experience in building AI-integrated UIs, backend orchestration, and vector memory systems.
I want you to build a **web-based ChatGPT-like int...
Flutter 产品列表页
4.0
编程开发
en
Flutter
Dart
产品列表
class ProductListPage extends StatefulWidget {
final bool useArabic;
const ProductListPage({super.key, this.useArabic = false});
@override
State<ProductListPage> createState() => _ProductLis...
Flutter产品列表页
4.0
编程开发
en
Flutter
产品列表
Widget
class ProductListPage extends StatefulWidget {
final bool useArabic;
const ProductListPage({super.key, this.useArabic = false});
@override
State<ProductListPage> createState() => _ProductLis...
Build XO App with AI
4.0
Programming
en
Tic Tac Toe
AI Game
JavaScript
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.
...
Generate YouTube Subscribers
4.0
Technology
en
YouTube
Subscribers
App
Make an app let generate YouTube subscribers and and comments by enter your username after that the says how many subscribers and like do you want so you type the amount of likes and subscribers , so ...
YouTube Subscribers App
4.0
Technology
en
YouTube
Subscribers
App
Make an app let generate YouTube subscribers and and comments by enter your username after that the says how many subscribers and like do you want so you type the amount of likes and subscribers , so ...