We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- React
- Data Handling
- Blog Post
- Discussions
Blog Post
Blog Post
Sort by
recency
|
26 Discussions
|
Please Login in order to post a comment
Need to move the to home component
This looks like a great little project for practicing React state management and component rendering! I like that it focuses on simple CRUD operations, which are perfect for learning the basics. Clearing the inputs after creating a post is a nice touch for UX too. If you’re new to React, this is a perfect challenge to get hands-on, give it a try and join the fun of building and managing your own mini blog app!
All time I entrie in this chalange give error. I tried in Chrome, Edge and Brave.
Easy solution just using 3 state variables, but surely can be optomized a lot.
Below is the code:
import React, { useState } from "react"; import Input from "./Input"; import PostDisplay from "./PostDisplay";
function Home() { const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [posts, setPosts] = useState([]);
const handlePost = () => { if (title !== "" && description !== "") { const id = posts.length; setPosts([...posts, { id: id, title: title, description: description }]); setTitle(""); setDescription(""); } }
const handleDeletePost = (id) => { const updatedPosts = posts.filter((item) => item.id !== id); setPosts([...updatedPosts]); }
return ( Create Post ); }
export default Home;