问题描述
我试图在单击按钮时在功能组件中获得相同的数字(输入和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>
);
}
据我了解,我需要再次调用该组件的渲染器,但是我不知道该怎么做。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)