⚛️ React Journey: useCallback – Stable Functions for Performance In React, functions get re-created on every render. Usually that’s fine, but when you pass functions to memoized child components or use them in useEffect dependencies, changing references can cause unnecessary re-renders or infinite loops. useCallback solves this by memoizing a function and only recreating it when its dependencies change. What useCallback does useCallback(fn, deps) returns the same function instance between renders until one of the dependencies changes. Syntax: const memoizedCallback = useCallback(() => { // logic }, [dependencies]); Think: useMemo for values, useCallback for functions. 🧠 When to use useCallback (and when not to) Use useCallback when: You pass a function to a memoized child component (React.memo). The function is used in a useEffect dependency array and you want to avoid re-running the effect unnecessarily. Don’t use it everywhere “by default” — it adds complexity. Reach for it when you actually hit performance or dependency issues. Have you faced unexpected re-renders or infinite loops because a function kept changing between renders? #React #useCallback #ReactHooks #Performance #JavaScript #Frontend #WebDevelopment #ReactBasics #DeveloperLife #Backend #FullStack #WebDevHumor #CodingLife #ProgrammerHumor #JavaScript #ReactJS #CSS #HTML #NodeJS #TechLife #DeveloperLife #SoftwareEngineering #Productivity #TechCommunity #LinkedInCreators #EngineeringCulture #Entri
Good trick
Yes. And thanks to usecallback which solves this unnecessary re rendering problem . And you always remember these concepts when you played with them and compare results with and without