如何获取功能组件中的当前状态值?

时间:2020-08-27 21:12:28

标签: reactjs state render react-component

我试图在单击按钮时在功能组件中获得相同的数字(输入和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>
 );
}

据我了解,我需要再次调用该组件的渲染器,但是我不知道该怎么做。

0 个答案:

没有答案