【发布时间】:2021-01-17 23:33:53
【问题描述】:
假设我要创建一个Converter,这意味着输入值应该根据另一个改变。
只是看看我想在行动中做什么https://calolocosta.github.io/romanNumeralsConverter/。
这是我迄今为止尝试过的,但无法成功
function LightBulb() {
let [input1, setInput1] = useState("");
let [input2, setInput2] = useState("");
const handleInput1 = (e) => {
setInput2(e.target.value);
};
const handleInput2 = (e) => {
setInput1(e.target.value);
};
return (
<div className="App">
<input
type="text"
value={input2}
onChange={(e) => handleInput1(e)}
placeholder="example 1000"
/>
<input
type="text"
value={input1}
onChange={(e) => handleInput2(e)}
placeholder="example MCMXC"
/>
</div>
);
}
所以我想要的是在 input1 键入时更改 input2 的值,反之亦然。 这是我一直在研究的代码框:https://codesandbox.io/s/react-hooks-usestate-forked-8o257,任何想法都会不胜感激。
【问题讨论】:
标签: reactjs forms react-hooks