Menu

useEffect Hook in React : Understand useEffect in a single article for beginners
πŸ“°

useEffect Hook in React : Understand useEffect in a single article for beginners

DEV Community: beginnersΒ·_sondos ChΒ·2 days ago
#weggPB3o
#devtobeginners#devto#dev#function#runs
Long article (669 words) β€” no AI summary yet.
Reading 0:00
15s threshold

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 () => { ...…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.