How to display a component for a single item of mapped data

Please I need help.

I want to display the orange input only the reply button of a single comment is clicked!

Could your comment component have some state that keeps track of whether Reply was clicked? Then you could conditionally display the orange box only when Reply was clicked.

It has but the comments are mapped and a reply is to be made based on a comment id so I also need to to show the reply input based on the comment id (for a single comment)

I’m having trouble understanding how this is set up. Could you post some of your code?


It starts from where I map the comments.

Thank you

/* eslint-disable no-unused-vars */
import { useState } from “react”;
import CustomIcon from “components/common/CustomIcon”;
import CommentForm from “./CommentForm”;
import { likePost } from “services/postService”;
import { timeSince } from “utils/helpers”;

import useUser from “hooks/useUser”;
import { Link } from “react-router-dom”;
import { postReply } from “services/repliesService”;

const CommentSection = ({ postId, comments, likes }) => {
const [isLiked, setIsLiked] = useState(false);
const [likesCount, setLikesCount] = useState(likes ? likes.length : 0);
const [showReply, setShowReply] = useState(false);
const [message, setMessage] = useState("");
const { user } = useUser();

const handleLikePost = async () => {
try {
const response = await likePost(postId);
} catch (ex) {

const handleSubmit = (e) => {

if (!comments) {
return null;

const handleReply = (commentId) => {
postReply(commentId, message)
.then((res) => {
if (res.ok) {

.catch((err) => console.log(err));

return (

{comments && comments.length} comments

{likesCount} likes

{comments &&, i) => (



{ setShowReply((prev) => !prev); }} > Reply

{showReply && (

{ setMessage(; }} /> )}
{timeSince(new Date(comment.createdAt))}
))} ); };

export default CommentSection;

So what I’m suggesting is that you could have a Comment component that keeps track of whether its own Reply has been clicked. In your map you would create each Comment. The showReply would be moved from CommentSection into the new Comment component.


But could you just help me with the way code (the way you would write it).