Header Ads Widget

Responsive Advertisement

Darshan industries

import { useState } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; export default function SocialMediaApp() { const [posts, setPosts] = useState([ { id: 1, user: "Amit", content: "Meri pehli post!" }, { id: 2, user: "Rahul", content: "Social media app working fine!" } ]); const [newPost, setNewPost] = useState(""); const [isLoggedIn, setIsLoggedIn] = useState(false); const [currentUser, setCurrentUser] = useState(null); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const login = () => { if (username.trim() && password.trim()) { setIsLoggedIn(true); setCurrentUser(username); setUsername(""); setPassword(""); } }; const logout = () => { setIsLoggedIn(false); setCurrentUser(null); }; const addPost = () => { if (newPost.trim() !== "") { const newEntry = { id: posts.length + 1, user: currentUser || "Guest", content: newPost }; setPosts([newEntry, ...posts]); setNewPost(""); } }; return (

Darshan Media

{!isLoggedIn ? (

Login to Post

setUsername(e.target.value)} placeholder="Username" /> setPassword(e.target.value)} placeholder="Password" />
) : (
)} {isLoggedIn && (
setNewPost(e.target.value)} placeholder="Aap kya soch rahe hain?" />
)}
{posts.map((post) => (

{post.user}

{post.content}

))}
); }

Post a Comment

0 Comments