下面只是一个重现此问题的简化虚拟示例.
function MultiplierBox() {
const [a, setA] = useState([1.0, 2.2])
function updateA(index, newValue) {
const newArray = [...a];
newArray[index] = newValue;
setA(newArray);
}
function Row({ a, index }) {
function handleA(event) {
const newValue = parseFloat(event.target.value)
updateA(index, newValue)
}
return <input type="number" value={a[index]} onChange={handleA} />
}
return (<div className="MultiplierBox">
{a}
<Row a={a} index={0} />
<Row a={a} index={1} />
</div>);
}
我try 了什么:
- 使用单个值而不是数组(有效)
- 已判断css样式规则
- 创建了问题的简化版本
我期望的是:
- 输入字段保持焦点