Created
April 1, 2022 05:29
-
-
Save fturkyilmaz/a7c4eff7236e6fb5448c311ea88fd087 to your computer and use it in GitHub Desktop.
React 18 Automatic Batching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logo from "./logo.svg"; | |
import "./App.css"; | |
import { useState, useEffect } from "react"; | |
function App() { | |
const [count, setCount] = useState(0); | |
const [flag, setFlag] = useState(false); | |
function handleClick() { | |
setCount((c) => c + 1); | |
setFlag((f) => !f); | |
} | |
useEffect(() => { | |
console.log(`Render count : ${count} Flag :${flag}`); | |
}); | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p> | |
Edit <code>src/App.js</code> and save to reload. | |
</p> | |
<a | |
className="App-link" | |
href="https://reactjs.org" | |
target="_blank" | |
rel="noopener noreferrer"> | |
Learn React | |
</a> | |
<button className="button" onClick={handleClick}> | |
Handle click | |
</button> | |
</header> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment