From 49984fbfa23c2ca0ea80a7143eb96e64e0d5673d Mon Sep 17 00:00:00 2001 From: Christopher-Martinez-422 <107010274+Christopher-Martinez-422@users.noreply.github.com> Date: Thu, 18 May 2023 12:06:53 -0700 Subject: [PATCH] first commit --- src/App.js | 17 ++++++++++++++++- src/components/Comments/Comments.js | 3 +++ src/components/Posts/LikeSection.js | 4 ++-- src/components/Posts/Post.js | 4 ++-- src/components/Posts/Posts.js | 3 +++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index 6409520c4..75ff605e7 100644 --- a/src/App.js +++ b/src/App.js @@ -5,15 +5,19 @@ */ // Import the state hook -import React from 'react'; +import React, { useState } from 'react'; // Import the Posts (plural!) and SearchBar components, since they are used inside App component +import Posts from './components/Posts/Posts' +import SearchBar from './components/SearchBar/SearchBar' // Import the dummyData +import dummyData from './dummy-data' import './App.css'; const App = () => { // Create a state called `posts` to hold the array of post objects, **initializing to dummyData**. // This state is the source of truth for the data inside the app. You won't be needing dummyData anymore. // To make the search bar work (which is stretch) we'd need another state to hold the search term. + const [posts, setPosts] = useState(dummyData); const likePost = postId => { /* @@ -27,11 +31,22 @@ const App = () => { - if the `id` of the post matches `postId`, return a new post object with the desired values (use the spread operator). - otherwise just return the post object unchanged. */ + const updatedPosts = posts.map(post => { + if (post.id === postId){ + return { ...post, likes: post.likes + 1} + }else { + return post; + } + }) + + setPosts(updatedPosts); }; return (
100 likes
+{numberOfLikes}
); }; diff --git a/src/components/Posts/Post.js b/src/components/Posts/Post.js index a57abde2f..48e6f6f51 100644 --- a/src/components/Posts/Post.js +++ b/src/components/Posts/Post.js @@ -21,9 +21,9 @@ const Post = props => { /> {/* Is LikeSection getting all the props it needs to work correctly? */} -