useEffectEvent in React 19.2 Explained with Example | New React Hook in Action
useEffectEvent in React 19.2
- What is useEffectEvent
- Problem Statement (Why we need useEffectEvent)
- Solution with useEffectEvent
- Interview Question
- Notes and code
Code used in this example :-
import { useEffectEvent } from "react";
import { useEffect, useState } from "react";
function App() {
const [count, setCount] = useState(0)
const countControl= useEffectEvent(()=>{
setCount(count + 1)
})
useEffect(() => {
// const internal =setInterval(() => {
// countControl()
// }, 1000)
// console.log(internal);
return ()=>clearInterval(internal)
}, [])
return (
<div>
<h1>{count}</h1>
</div>
);
}
export default App;