You are viewing a single comment's thread. Return to all comments →
I am seeing it ok but is not working, do i need to do something with the test-id as well
` Home
import React from "react"; import Input from "./Input"; import PostDisplay from "./PostDisplay";
function Home() { const [formData, setFormData] = React.useState({ title: '', description: '' });
const [posts, setPosts] = React.useState([]);
const handleStateChange = (updatedData) => { setFormData(prevState => ({ ...prevState, ...updatedData, })) }
const {title, description} = formData
const validData = () => !!title && !!description;
const handleCreatePost = () => { if (validData()) { setPosts([...posts, formData]) setFormData({ title: '', description: '' }) } }
const handleDeletePost = (index) => { setPosts(posts.filter((_, i) => i !== index)) }
return ( Create Post {posts.map((post, index) => ( handleDeletePost(index)}/> ))} ); }
export default Home;
INPUT
import React from "react";
function Input({formData, onStateChange }) { const handleState = (event) => { event.preventDefault() const { name, value } = event.target onStateChange({ [name]: value }) };
return ( ); }
export default Input;
POSTDISPLAY
function PostDisplay({formData, onDelete}) { const {title, description} = formData return (
{description}
export default PostDisplay;
`
Seems like cookies are disabled on this browser, please enable them to open this website
Blog Post
You are viewing a single comment's thread. Return to all comments →
I am seeing it ok but is not working, do i need to do something with the test-id as well
` Home
import React from "react"; import Input from "./Input"; import PostDisplay from "./PostDisplay";
function Home() { const [formData, setFormData] = React.useState({ title: '', description: '' });
const [posts, setPosts] = React.useState([]);
const handleStateChange = (updatedData) => { setFormData(prevState => ({ ...prevState, ...updatedData, })) }
const {title, description} = formData
const validData = () => !!title && !!description;
const handleCreatePost = () => { if (validData()) { setPosts([...posts, formData]) setFormData({ title: '', description: '' }) } }
const handleDeletePost = (index) => { setPosts(posts.filter((_, i) => i !== index)) }
return ( Create Post {posts.map((post, index) => ( handleDeletePost(index)}/> ))} ); }
export default Home;
INPUT
import React from "react";
function Input({formData, onStateChange }) { const handleState = (event) => { event.preventDefault() const { name, value } = event.target onStateChange({ [name]: value }) };
return ( ); }
export default Input;
POSTDISPLAY
import React from "react";
function PostDisplay({formData, onDelete}) { const {title, description} = formData return (
{title}
{description}
Delete ); }export default PostDisplay;
`
`