definition :
is a react hook (function provided by react) that lets you synchronize with an external system (like : fetch data from server or local storage , server connection , β¦)
syntax :
useEffect(callback function , dependency list) : void
callback : Holds your side-effect logic. Unlike the component render body (which must remain pure), this function interacts with external systems, browser APIs, or outside state, so it is impure by nature.
Execution timing :Runs after the component renders and updates the screen. While it usually executes after the browser paints, updates triggered by direct user interactions (such as a click) may run before painting ,if you need code to run strictly before the browser paints, use useLayoutEffect . Synchronous code inside the effect runs immediately, whereas asynchronous operations (such as network requests) are handed off to the browser and handled via the JavaScript event loop see Event Loop details here .
Cleanup function (optional) : Can return () => { ...β¦