Day 32 of Posting React Content 🧠 What is useCallback? 🎓 Imagine This You enter your college every day. The security guard checks your ID card. You don't explain who you are every time. You just show the same ID card. 💡 In React Sometimes a parent component sends a function to a child component. When React renders again, that function gets created again and again. useCallback prevents this. It keeps the same function and reuses it until something changes. ✨ One Line Understanding Normal React → function recreated every render useCallback → same function reused #ReactJS #ReactHooks #useCallback #FrontendDevelopment #JavaScript #LearnInPublic #CodingJourney #WebDevelopment
Prevent Function Recreation with useCallback in React
More Relevant Posts
-
🚀 DAY 40 OF POSTING REACT CONTENT 🎛️ CONTROLLED vs UNCONTROLLED COMPONENTS 🤔 🧠 Imagine This You are typing your name in a form. 👉 Case 1: Every letter you type is saved instantly 👉 Case 2: You type freely… and value is checked only after you finish 💡 In React 👉 Controlled Component React stores value on every keystroke (using state) 👉 Uncontrolled Component Value stays inside input, React reads it only when needed (using ref) ✨ One Line Understanding Controlled → React always knows the value Uncontrolled → React checks value when needed #ReactJS #ReactForms #ControlledComponents #FrontendDevelopment #JavaScript #LearnInPublic #CodingJourney #WebDevelopment
To view or add a comment, sign in
-
-
🔒 React sanitizes user input automatically. But one line can break everything. Normal rendering? You're safe. <p>{userInput}</p> // React escapes this. Always . The moment you do this — you're on your own: dangerouslySetInnerHTML={{ __html: userInput }} The word "dangerous" is literally in the name. React is warning you. Always pair it with DOMPurify. And never trust user-controlled URLs — a javascript: href executes on click. React is secure by default. Just don't fight against it. Ever used dangerouslySetInnerHTML in production? 👇 #ReactJS #WebSecurity #Frontend #JavaScript
To view or add a comment, sign in
-
-
Today something interesting happened while I was building a Custom Date Picker in NextJS.🗓 I have used useRef many times before, but honestly I was mostly using it without fully understanding the concept behind it But today… it finally clicked.💫 While implementing the feature, I realized that: • useRef creates a mutable object • The value is stored inside .current • The value persists between renders • Updating .current does not trigger a re-render • It can also be used to directly access DOM elements The most interesting part for me was understanding why React doesn't re-render when current changes. Sometimes you don’t truly understand a concept until you build something real with it. Small learning today, but a very satisfying one. 💫 What was the React concept that took you the longest to understand❓️ #React #JavaScript #FrontendDevelopment #ReactHooks #BuildInPublic #LearningJourney
To view or add a comment, sign in
-
Why does React say: "Don't call hooks conditionally"? 🤔 Let’s break it down simply. React doesn’t track hooks by name. It tracks them by order. Every render, React just walks through hooks like this: 1st hook → 2nd hook → 3rd hook That’s it. No labels. No IDs. Just position. Now imagine this 👇 if (condition) { useEffect(() => { // do something }); } 👉 First render: Hook1 → Hook2 → Hook3 👉 Next render (condition = false): Hook1 → Hook3 Now React gets confused 😵 It expects Hook2… but suddenly sees Hook3. This breaks the internal hook mapping — and boom 💥 unexpected bugs or crashes. 👉 The rule exists because hooks must run in the same order on every render. That’s why: ❌ No hooks inside conditions ❌ No hooks inside loops ❌ No hooks inside nested functions 👉 Always call hooks at the top level. Once you understand this, React hooks feel much less “magical” and more predictable. #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #LearnInPublic
To view or add a comment, sign in
-
Routing in React - Today I explored how navigation works in React using React Router. Routing allows us to switch between pages without reloading the entire website, making applications faster and smoother. Key Concepts I Learned: • Setting up routes using BrowserRouter • Navigating using Link • Dynamic routing using parameters • Redirecting with useNavigate One important takeaway: React applications are Single Page Applications (SPA), where components change instead of full page reloads. #ReactJs #webdevelopment #javascript #coding
To view or add a comment, sign in
-
-
Today I learned about Conditional Rendering in React. Conditional rendering allows us to display different UI elements based on conditions. For example: A user logged in → Show dashboard A user not logged in → Show login button While fetching data → Show loading text React uses methods like ternary operators, && operator, and if-else conditions to handle this. This helps in building dynamic and interactive user interfaces. Up Next: Lists & Keys 👀 React Series – Day 7 🚀 #ReactJS #LearningInPublic #WebDevelopment #FrontendDeveloper #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
-
Stop nesting your async calls in React! 🛑 Using async/await within a clean useEffect structure (or a custom hook) keeps your code readable, maintainable, and much easier to debug. What's your biggest React pet peeve? 👇 #ReactJS #CleanCode #JavaScript #softwaredevelopment #React
To view or add a comment, sign in
-
-
Today I learned about Lists & Keys in React. Lists allow us to render multiple items dynamically using methods like map(). For example: We can display a list of users, products, or tasks easily. Keys are used to uniquely identify each item in a list. This helps React efficiently update only the changed elements instead of re-rendering everything. Using unique keys improves performance and avoids bugs. Up Next: Forms in React 👀 React Series – Day 8 🚀 #ReactJS #LearningInPublic #WebDevelopment #FrontendDeveloper #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
-
Today while building a pagination component in React, I came across the use of Array.from() in JavaScript. The problem I was facing was simple: I wanted to show page numbers between the Previous and Next buttons. For example: Prev 1 2 3 4 5 Next At first, I was thinking about how to generate those numbers dynamically instead of writing them manually. That’s when I came across Array.from(). It helped me create an array of a specific length and then generate page numbers from it. Something like this: Array.from({ length: totalPages }, (_, i) => i + 1) This creates: [1, 2, 3, 4, 5] Which can then be mapped easily to render pagination buttons in React. A small thing, but it made pagination logic feel much cleaner and more dynamic. Am I understanding this correctly? Would love to know if there’s a better or more practical way you usually handle pagination numbers. #JavaScript #ReactJS #WebDevelopment #Frontend #Pagination
To view or add a comment, sign in
-
-
🚫 Do Not Overuse <div> in React When working with HTML, we often use <div> to wrap multiple elements. But in React, unnecessary <div> elements can create extra nodes in the DOM. 💡 React introduced Fragments (React 16.2) to solve this problem. Why use React Fragments? • No extra DOM nodes • Cleaner and less cluttered DOM • Slightly better performance • Easy way to group multiple elements React also provides a Fragment shorthand (<> </>) which makes code cleaner and easier to write. 📌 I’ve explained this concept in a simple swipe PDF for beginners. #React #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #MohitDecodes
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development