Skip to content

Commit

Permalink
[#65903] do not store components as state in YCommentsParent
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Oct 14, 2024
1 parent 81001e1 commit fcc26fe
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/components/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,8 @@ const PopupButton = ({ icon, onClick, text, bgOnHover }) => {

/** @param {{ ycomments: YComments }} */
export const YCommentsParent = ({ ycomments, collaboration }) => {
let createWidget = ({ commentId }) => <YComment {...{ key: commentId, commentId, ycomments, collaboration }} />;
let createWidgets = () => ycomments.iterComments().map(createWidget);
let [widgets, setWidgets] = useState(createWidgets());
const [comments, setComments] = useState(ycomments.iterComments());
useEffect(() => ycomments.display().onUpdate(() => setComments(ycomments.iterComments())), [ycomments]);

ycomments.display().onUpdate(() => setWidgets(createWidgets()));

return <>{widgets}</>;
return comments.map(({ commentId }) => <YComment key={commentId} {...{ commentId, ycomments, collaboration }} />);
};

0 comments on commit fcc26fe

Please sign in to comment.