我的输入标签在这里:
<Input
value={isNaN(currentCount) ? '' : currentCount}
onKeyUp={(e) => {
onKeyup(e);
if (e.key === 'Enter') {}
}}
onChange={(e) => {
handleChange(e);
}}
/>onKeyUp正在工作,但onChange现在不能工作。
我发现,当我在文本框中输入一个值时,输入标记的值不会改变。
如果你和我有同样的问题,请告诉我,或者知道如何解决。
发布于 2022-10-17 11:48:25
您应该创建一个状态并在其中设置输入值,如下所示:
const [value, setValue] = useState('')
const onChange = (event) => {
setValue(event.target.value)
}
return (
<Input
value={value}
onKeyUp={(e) => {
onKeyup(e);
if (e.key === 'Enter') {}
}}
onChange={handleChange}
/>
)发布于 2022-10-17 11:59:43
const [ currentCount, setCurrentCount] = useState('');
const handleChange = (e) => {
setCurrentCount( e.target.value || '');
}
return (
<input type="text" value={ isNaN(currentCount) ? '' : currentCount } onChange={ (e) => handleChange(e) }/>
)https://stackoverflow.com/questions/74096470
复制相似问题