import React, { useEffect, useMemo, useContext } from 'react'; import 'prismjs/components/prism-markdown.js'; import { IProps } from '../../utils'; import { EditorContext, ContextStore } from '../../Context'; import Markdown from './Markdown'; import Textarea from './Textarea'; export interface ITextAreaProps extends Omit, 'value' | 'onChange' | 'onScroll'>, IProps { onScroll?: (e: React.UIEvent) => void; value?: string; } export type TextAreaRef = { text?: HTMLTextAreaElement; warp?: HTMLDivElement; }; export default function TextArea(props: ITextAreaProps) { const { prefixCls, className, onScroll, ...otherProps } = props || {}; const { scrollTop, dispatch } = useContext(EditorContext); const warp = React.createRef(); useEffect(() => { const state: ContextStore = {}; if (warp.current) { state.textareaWarp = warp.current || undefined; warp.current.scrollTop = scrollTop || 0; } if (dispatch) { dispatch({ ...state }); } }, []); return useMemo( () => (