我试图在单击按钮时在功能组件中获得相同的数字(输入和div),可以吗?
function App() {
let [someState, setSomeState] = useState(5)
let [otherSomeState, setOtherSomeState] = useState(7)
let stateChanger = () => {
setSomeState(otherSomeState + someState)
setOtherSomeState(someState)
}
return (
<div className="App">
<div>{someState}</div>
<input value={otherSomeState} onChange={ ()=>false } />
<button onClick={ ()=>stateChanger() }>Add</button>
</div>
);
}
据我了解,我需要再次调用该组件的渲染器,但是我不知道该怎么做。