From 2d89d2057b9f28a8fc1e8c3104f697467029198f Mon Sep 17 00:00:00 2001 From: fantasticit Date: Wed, 13 Apr 2022 20:31:57 +0800 Subject: [PATCH] refactor: memorize function --- .../src/tiptap/wrappers/iframe/index.tsx | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/client/src/tiptap/wrappers/iframe/index.tsx b/packages/client/src/tiptap/wrappers/iframe/index.tsx index 21ef070b..aedf845e 100644 --- a/packages/client/src/tiptap/wrappers/iframe/index.tsx +++ b/packages/client/src/tiptap/wrappers/iframe/index.tsx @@ -1,6 +1,7 @@ -import { NodeViewWrapper, NodeViewContent } from '@tiptap/react'; +import { useCallback, useMemo } from 'react'; import cls from 'classnames'; -import { Input, Typography, Space } from '@douyinfe/semi-ui'; +import { NodeViewWrapper, NodeViewContent } from '@tiptap/react'; +import { Typography } from '@douyinfe/semi-ui'; import { Resizeable } from 'components/resizeable'; import styles from './index.module.scss'; @@ -10,21 +11,25 @@ export const IframeWrapper = ({ editor, node, updateAttributes }) => { const isEditable = editor.isEditable; const { url, width, height } = node.attrs; - const onResize = (size) => { + const onResize = useCallback((size) => { updateAttributes({ width: size.width, height: size.height }); - }; - const content = ( - - {url ? ( -
- -
- ) : ( -
- 请设置外链地址 -
- )} -
+ }, []); + + const content = useMemo( + () => ( + + {url ? ( +
+ +
+ ) : ( +
+ 请设置外链地址 +
+ )} +
+ ), + [url] ); if (!isEditable && !url) {