mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor Post.jsx with memoization
This commit is contained in:
@@ -1,18 +1,21 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
||||||
import breaks from 'remark-breaks';
|
import breaks from 'remark-breaks';
|
||||||
|
|
||||||
|
|
||||||
const customSchema = {
|
const Post = ({ content }) => {
|
||||||
|
const doubleNewlineContent = useMemo(() => content?.replaceAll(/\n(?!\n)/g, '\n\n'), [content]);
|
||||||
|
|
||||||
|
const customSchema = useMemo(() => ({
|
||||||
...defaultSchema,
|
...defaultSchema,
|
||||||
tagNames: [...defaultSchema.tagNames, 'div'],
|
tagNames: [...defaultSchema.tagNames, 'div'],
|
||||||
attributes: {
|
attributes: {
|
||||||
...defaultSchema.attributes,
|
...defaultSchema.attributes,
|
||||||
div: ['className'],
|
div: ['className'],
|
||||||
},
|
},
|
||||||
};
|
}), []);
|
||||||
|
|
||||||
|
|
||||||
const blockquoteToGreentext = () => (tree) => {
|
const blockquoteToGreentext = () => (tree) => {
|
||||||
@@ -91,10 +94,6 @@ const createQuotelink = (children) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Post = ({ content }) => {
|
|
||||||
const doubleNewlineContent = content?.replaceAll(/\n(?!\n)/g, '\n\n');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
children={doubleNewlineContent}
|
children={doubleNewlineContent}
|
||||||
|
|||||||
Reference in New Issue
Block a user