import { Input } from 'antd'; import clsx from 'clsx'; import React, { useState } from 'react'; import { useWatch } from '../hooks/useWatch'; interface EditableTextProps { className?: string; enable?: boolean; defaultValue: string; onSave: (text: string) => void; } export const EditableText: React.FC = React.memo((props) => { const [text, setText] = useState(props.defaultValue); const enable = props.enable ?? true; useWatch([props.defaultValue], () => { setText(props.defaultValue); }); return ( <> {enable ? ( setText(e.target.value)} onBlur={(e) => props.onSave(e.target.value)} /> ) : ( {text} )} ); }); EditableText.displayName = 'EditableText';