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
|
11 Discussions
|
Please Login in order to post a comment
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;
`
`
Anybody know, why I don't have anything in 'app.test.jsx' file? File is empty. Also it is showing below console error.
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: Object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
I was able to solve this problem in my local but not able to run in this platform with the same solution.
Home.js
Input
PostDisplay
This project is a great way to build a solid understanding of React and apply your knowledge in a practical setting. 11xplay.online pro
Home
Input
Posts Display