import React, { useState } from 'react';
const CommentList = ({ comments, showAnswerInput }) => {
return (
<div style={
{ marginLeft: '20px' }}>
{comments.map((comment) => {
return (
<div key={comment.id}>
{comment.name}:{comment.content}
<button
onClick={() => {
showAnswerInput(comment.id);
}}
>
回复
</button>
{comment.children && (
<CommentList comments={comment.children} showAnswerInput={showAnswerInput} />
)}
</div>
);
})}
</div>
);
};
export default function Test() {
const [user, setUser] = useState('张三');
const [input, setInput] = useState();
const [isShow, setIsShow] = useState(false);
const [comme
React 实现无限层级评论功能
最新推荐文章于 2024-05-02 18:12:22 发布