Skip to content

Commit 50e65aa

Browse files
committed
Написал функцию для корректного отображения комментариев с примененными стилями текста
1 parent 7839869 commit 50e65aa

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/features/comments/CommentView.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/no-danger */
12
import { useAuth } from 'common/context/Auth/useAuth';
23
import PropTypes from 'prop-types';
34
import styled from 'styled-components';
@@ -108,6 +109,10 @@ export const CommentView = ({ comment, lastComment }) => {
108109
setIsAuthorizePopoverEnable(!isAuthorizePopoverEnable);
109110
};
110111

112+
function createMarkup() {
113+
return { __html: lastComment ? truncateLongText(comment.text) : comment.text };
114+
}
115+
111116
return (
112117
<Wrapper>
113118
<div className="row align-items mb-4 g-1">
@@ -121,7 +126,7 @@ export const CommentView = ({ comment, lastComment }) => {
121126
<span>{comment.author?.name}</span>
122127
<StyledTime>{dayjs(comment.createdAt).fromNow()}</StyledTime>
123128
</div>
124-
<div>{lastComment ? truncateLongText(comment.text) : comment.text}</div>
129+
<div dangerouslySetInnerHTML={createMarkup()} />
125130
{!lastComment && (
126131
<StyledCommentActions>
127132
<CommentsActions commentId={comment._id} />

0 commit comments

Comments
 (0)