Open Yanqi-Lin opened 3 weeks ago
请问有解决吗?把他单独抽成受控组件也无法解决问题
import React, { useRef, useState } from 'react'; import { Input } from 'antd';
const InputHoc: React.FC<{
value?: string;
onChange?: any;
}> = ({ value, onChange }) => {
const ref = useRef(null);
const [inputValue, setInputValue] = useState
const handleInputChange = (e: React.ChangeEvent
const handleInputConfirm = () => { if (inputValue) { onChange?.(inputValue); } };
return ( <Input ref={ref} type="text" value={inputValue} onChange={handleInputChange} onBlur={handleInputConfirm} onPressEnter={handleInputConfirm} /> ); };
export default InputHoc; 官方有一个受控组件的写法,通过onBlur和onPressEnter进行onchange提交,试了下可行
🐛 bug 描述
正常进行连续输入:
出现bug,输入中断,保存为拼音:
📷 复现步骤
可见:https://codesandbox.io/s/modest-dew-7r5ghf?file=/App.tsx
🏞 期望结果
输入不发生中断
💻 复现代码
可见:https://codesandbox.io/s/modest-dew-7r5ghf?file=/App.tsx
© 版本信息