it is it used to monitor the state in functional component. the only to implement state is to use useState hook
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import React, { useState } from 'react'; import ReactDOM from 'react-dom/client'; //App function component function App() { const [value, setValue] = useState(1) return ( <> <h2>react useState hook example</h2> <h2>value changes on button click is : {value}</h2> <button onClick={() => setValue(value + 1)}> click</button> </> ); } export default App; const root = ReactDOM.createRoot(document.getElementById("root")); //creating a root React component in your application root.render(<App />) // rendering React components into a DOM node. |
Output:
