import React, { useContext, useEffect, useMemo } from 'react'; import { IProps } from '../../utils'; import { EditorContext } from '../../Context'; import { TextAreaCommandOrchestrator } from '../../commands'; import handleKeyDown from './handleKeyDown'; import shortcuts from './shortcuts'; export interface TextAreaProps extends Omit, 'value' | 'onChange'>, IProps { onChange?: (event: React.ChangeEvent) => void; } export default function Textarea(props: TextAreaProps) { const { prefixCls, ...other } = props; const { markdown, commands, tabSize, onChange, dispatch } = useContext(EditorContext); const textRef = React.createRef(); const executeRef = React.useRef(); useEffect(() => { if (textRef.current && dispatch) { const commandOrchestrator = new TextAreaCommandOrchestrator(textRef.current); executeRef.current = commandOrchestrator; dispatch({ textarea: textRef.current, commandOrchestrator }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return useMemo( () => (