useRef doesn't trigger re-renders. Here's why - useRef just returns this: { current: value } A plain object. Nothing reactive about it. Changing ref.current = newValue is like editing a JS object property. React has no idea it happened. useState is different — setState notifies React's scheduler. That notification is what causes a re-render. useRef skips that notification entirely. By design. Use it for: ✅ DOM refs (input.focus()) ✅ Timer IDs (clearInterval) ✅ Previous values ✅ Anything your logic needs but the UI doesn't Simple mental model: useState → remember + re-render useRef → remember silently #React #JavaScript #Frontend #ReactHooks
React useRef: Silent State Updates
More Relevant Posts
-
If you think every re-render updates the DOM, this will change your mind. Rendering in React is just a function call. Your component runs, returns JSX, and React calculates what the UI should look like. That’s it. Now the important part 👇 Re-rendering does NOT mean the DOM was updated. It only means 👉 React called your component again The DOM is updated later and only if something actually changed. So the real flow is: Trigger → state or props change Render → React runs your component Commit → React updates only the differences This is why you can type inside an input, the component re-renders, and your text is still there. Because React doesn’t touch what hasn’t changed. The real optimization isn’t avoiding re-renders It’s understanding what happens after them. #React #FrontendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #ReactJS #FrontendEngineer #TechCareers #CodingTips #DeveloperMindset
To view or add a comment, sign in
-
-
🚀 Debounce vs Throttle in React (and when to use each) Handling user interactions efficiently is key to building performant applications — especially when dealing with frequent events like typing and scrolling. Here’s a simple breakdown: 🔹 Debounce • Delays execution until the user stops triggering the event • Best for: search inputs, API calls on typing 🔹 Throttle • Limits execution to once every fixed interval • Best for: scroll events, resize handlers ⚠️ Without control, frequent events can lead to: • Too many API calls • UI lag • Performance issues 📈 Results: • Reduced unnecessary API requests • Improved UI responsiveness • Better user experience 💡 Key takeaway: Use debounce when you want the final action, use throttle when you want continuous control. What scenarios have you used debounce or throttle in? #React #Frontend #WebDevelopment #Performance #JavaScript #NextJS
To view or add a comment, sign in
-
-
Hydration issues in Next.js can break your UI silently. No errors. Just weird behavior. Here’s why 👇 Server renders HTML. Client re-renders same component. If output differs: ❌ Hydration mismatch Common causes: ✖ Using random values (Math.random, Date.now) ✖ Accessing window during SSR ✖ Conditional rendering differences Result: → UI flicker → Unexpected bugs What works: ✔ Keep server & client output consistent ✔ Move client-only logic inside useEffect ✔ Avoid non-deterministic values Key insight: SSR means your code runs twice. If results differ… Your UI becomes unpredictable. #NextJS #ReactJS #Frontend #SSR #JavaScript #SoftwareEngineering #Debugging #Engineering #WebDevelopment
To view or add a comment, sign in
-
🚀 Improving Frontend Performance with Throttling & Debouncing One key realization while optimizing UI performance 👇 👉 Not all issues are about page load 👉 Many come from how frequently our code runs 🧠 The Problem Events like scroll 📜, resize 📏, and typing ⌨️ can fire hundreds of times per second This leads to: ❌ unnecessary work ❌ busy main thread ❌ poor responsiveness ⚙️ The Solution 🔹 Throttling 👉 Limit execution frequency 👉 e.g., run once every second 🔹 Debouncing 👉 Execute only after user stops 👉 e.g., search after typing stops 🎯 Key Difference 👉 Throttle = steady control 👉 Debounce = wait then act 📊 Why it matters 👉 Less work for browser 🧠 👉 Better responsiveness ⚡ 💡 “Performance is not just faster loading — it’s smarter execution.” #Frontend #JavaScript #WebPerformance #ReactJS #FrontendEngineering
To view or add a comment, sign in
-
My list UI was behaving weirdly… items were changing unexpectedly 😅 Yes, seriously. At first, I thought it was a state issue. But the problem was something very simple. 💡 I was doing this: {items.map((item, index) => ( Seemed fine… right? ❌ ⚠️ This caused: • Wrong UI updates • Items swapping incorrectly • Hard-to-debug bugs 💡 Then I fixed it: 👉 Used a unique and stable key 🧠 Example: {items.map((item) => ( ✅ Result: • Correct UI updates • No unexpected behavior • Predictable rendering 🔥 What I learned: Keys are not just for React warnings 👉 they control how React updates the UI 💬 Curious: Do you still use index as key… or avoid it? #ReactJS #FrontendDeveloper #JavaScript #CodingTips #WebDevelopment
To view or add a comment, sign in
-
React keeps two copies of your UI in memory and swaps them after every commit. That's double buffering. Part 2 goes deeper: priority lanes, where hooks actually live, the three sub-phases of the commit, and why React can pause rendering mid-tree. Read more: https://lnkd.in/ddqhgxHZ #React #Fiber #rendering #reconciliation #JavaScript #WebDev #SoftwareEngineering #BuildInPublic
To view or add a comment, sign in
-
-
Everyone is experimenting with this new text engine. Here is what it actually looks like in a real UI. Text reflows around moving elements in real time. Smooth, no layout breaks. I built an interactive demo 👇 https://lnkd.in/ezshxrKB Built with Pretext by Cheng Lou: https://lnkd.in/eex7dUWH Would you use this in production? #Frontend #JavaScript #WebDev #BuildInPublic #Pretext
To view or add a comment, sign in
-
✨ 𝗗𝗮𝘆 𝟱 𝗼𝗳 𝗠𝘆 𝗥𝗲𝗮𝗰𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 ⚛️🚀 Today I explored what happens 𝗯𝗲𝗵𝗶𝗻𝗱 𝘁𝗵𝗲 𝘀𝗰𝗲𝗻𝗲𝘀 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 — 𝗥𝗲𝗰𝗼𝗻𝗰𝗶𝗹𝗶𝗮𝘁𝗶𝗼𝗻, 𝗙𝗶𝗯𝗲𝗿, 𝗗𝗶𝗳𝗳𝗶𝗻𝗴, 𝗮𝗻𝗱 𝗞𝗲𝘆𝘀. I learned that when state changes, React doesn’t update the whole DOM. Instead, it compares the previous and new Virtual DOM using a 𝗱𝗶𝗳𝗳𝗶𝗻𝗴 𝗮𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺, and updates only what actually changed. The idea of 𝗥𝗲𝗰𝗼𝗻𝗰𝗶𝗹𝗶𝗮𝘁𝗶𝗼𝗻 — deciding what needs to update — was really interesting. And 𝗥𝗲𝗮𝗰𝘁 𝗙𝗶𝗯𝗲𝗿 takes it further by making rendering more efficient and interruptible, so the UI stays smooth. Also understood why 𝗸𝗲𝘆𝘀 are important when rendering lists. They help React identify elements correctly and avoid unnecessary re-renders. It’s fascinating to see how much optimization is happening behind such simple code. React is smarter than it looks 💻⚡ #ReactJS #JavaScript #WebDevelopment #LearningJourney #FrontendDevelopment
To view or add a comment, sign in
-
-
✨ 𝗗𝗮𝘆 𝟳 𝗼𝗳 𝗠𝘆 𝗥𝗲𝗮𝗰𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 ⚛️🚀 Today I learned about the `𝘂𝘀𝗲𝗥𝗲𝗳` 𝗵𝗼𝗼𝗸, and it felt a bit different from other hooks. Unlike state, updating a ref doesn’t trigger a re-render. That makes it useful for storing values that need to persist between renders without affecting the UI. I also learned how `useRef` can directly access DOM elements, which is helpful for things like focusing inputs, managing scroll, or interacting with elements when needed. What stood out to me is how React gives controlled ways to interact with the DOM without breaking its flow. #ReactJS #JavaScript #WebDevelopment #LearningJourney #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 𝗕𝘂𝗶𝗹𝘁 & 𝗣𝘂𝗯𝗹𝗶𝘀𝗵𝗲𝗱: 𝘂𝘀𝗲-𝘁𝗵𝗲𝗺𝗲-𝗺𝗼𝗱𝗲 🌗 𝘈 𝘭𝘪𝘨𝘩𝘵𝘸𝘦𝘪𝘨𝘩𝘵 𝘙𝘦𝘢𝘤𝘵 𝘩𝘰𝘰𝘬 𝘧𝘰𝘳 𝘥𝘢𝘳𝘬/𝘭𝘪𝘨𝘩𝘵 𝘮𝘰𝘥𝘦 Dark mode shouldn’t be complicated or overly opinionated. That’s why I built 𝘂𝘀𝗲-𝘁𝗵𝗲𝗺𝗲-𝗺𝗼𝗱𝗲, an open‑source React hook that focuses purely on 𝘁𝗵𝗲𝗺𝗲 𝘀𝘁𝗮𝘁𝗲 𝗺𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁, while giving developers full control over styling. ✅ 𝗪𝗵𝗮𝘁 𝗶𝘁 𝗵𝗮𝗻𝗱𝗹𝗲𝘀 𝗼𝘂𝘁 𝗼𝗳 𝘁𝗵𝗲 𝗯𝗼𝘅: • Light and dark theme switching • System preference detection (prefers-color-scheme) • Persistent theme using localStorage • Cross‑tab theme synchronization • SSR‑safe (works with Next.js) • Zero runtime dependencies You control the UI. The hook handles the logic. 🔗 𝗟𝗶𝘃𝗲 𝗗𝗲𝗺𝗼: https://lnkd.in/d2AprnYd 📝 𝗙𝘂𝗹𝗹 𝘁𝗲𝗰𝗵𝗻𝗶𝗰𝗮𝗹 𝗯𝗹𝗼𝗴 𝗼𝗻 𝗗𝗘𝗩.𝘁𝗼: https://lnkd.in/d78gT_zB 📦 𝗻𝗽𝗺 𝗽𝗮𝗰𝗸𝗮𝗴𝗲: https://lnkd.in/dHF6iM7T This project was a great learning experience around: • npm publishing & versioning • token‑based npm security • documentation & demos • shipping production‑ready open source Feedback, suggestions, and contributions are always welcome 🚀 #React #JavaScript #Frontend #OpenSource #WebDevelopment #NPM #DarkMode #OSS
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
Nice