mirror of https://github.com/fantasticit/think.git
refactor: memorize function
This commit is contained in:
parent
0337629d75
commit
2d89d2057b
|
@ -1,6 +1,7 @@
|
||||||
import { NodeViewWrapper, NodeViewContent } from '@tiptap/react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import cls from 'classnames';
|
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 { Resizeable } from 'components/resizeable';
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
|
||||||
|
@ -10,21 +11,25 @@ export const IframeWrapper = ({ editor, node, updateAttributes }) => {
|
||||||
const isEditable = editor.isEditable;
|
const isEditable = editor.isEditable;
|
||||||
const { url, width, height } = node.attrs;
|
const { url, width, height } = node.attrs;
|
||||||
|
|
||||||
const onResize = (size) => {
|
const onResize = useCallback((size) => {
|
||||||
updateAttributes({ width: size.width, height: size.height });
|
updateAttributes({ width: size.width, height: size.height });
|
||||||
};
|
}, []);
|
||||||
const content = (
|
|
||||||
<NodeViewContent as="div" className={cls(styles.wrap, 'render-wrapper')}>
|
const content = useMemo(
|
||||||
{url ? (
|
() => (
|
||||||
<div className={styles.innerWrap} style={{ pointerEvents: !isEditable ? 'auto' : 'none' }}>
|
<NodeViewContent as="div" className={cls(styles.wrap, 'render-wrapper')}>
|
||||||
<iframe src={url}></iframe>
|
{url ? (
|
||||||
</div>
|
<div className={styles.innerWrap} style={{ pointerEvents: !isEditable ? 'auto' : 'none' }}>
|
||||||
) : (
|
<iframe src={url}></iframe>
|
||||||
<div className={styles.emptyWrap}>
|
</div>
|
||||||
<Text>请设置外链地址</Text>
|
) : (
|
||||||
</div>
|
<div className={styles.emptyWrap}>
|
||||||
)}
|
<Text>请设置外链地址</Text>
|
||||||
</NodeViewContent>
|
</div>
|
||||||
|
)}
|
||||||
|
</NodeViewContent>
|
||||||
|
),
|
||||||
|
[url]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isEditable && !url) {
|
if (!isEditable && !url) {
|
||||||
|
|
Loading…
Reference in New Issue